How to Fix SSH Client_loop: send disconnect: Broken pipe Error

SSH, an acronym for Secure Shell, is a remote network protocol that is used to securely connect to remote devices such as servers and network devices over a TCP/IP network.

It is a cryptographic network protocol that provides strong encryption technologies and hashing to secure communication between two devices on a network.

SSH uses two main authentication methods: password authentication and public key authentication. With password authentication, a user provides the remote host’s IP address or FQDN (Fully Qualified Domain Name) and password to authenticate.

Public key authentication uses an SSH key pair for authentication, which comprises two SSH keys: private and public keys.

The private key resides on the user’s machine and should always be kept confidential and secure. The public key is saved on the remote host that a user connects to. During authentication, the identity of the two keys is compared and access is granted.

When connecting to a remote system via SSH, you might encounter the error Client_loop: send disconnect: Broken pipe.

Client_loop: send disconnect: Broken pipe Error
Client_loop: send disconnect: Broken pipe Error

In this tutorial, we will see why this happens and address the error.

Client_loop: send disconnect: Broken pipe Error

The error is simply a disconnection message that notifies you that your SSH connection timeout has been exceeded.

This is a period of inactivity during which no Linux command is executed or issued from the client side. When this happens, the SSH session is terminated, effectively disconnecting you from the remote server.

Most users will usually press ‘ENTER’ or a key on the keyboard to avoid having an idle SSH session which will cause the disconnection to the host. However, this can tedious and time-wasting.

Thankfully, SSH default configuration settings provide a few parameters that you can configure to keep your SSH connections active for longer periods of time.

Fix Client_loop: send disconnect: Broken pipe Error

To resolve this issue, you need to increase the SSH connection timeout on the client. To do so, modify the default SSH configuration file which is usually at /etc/ssh/sshd_config.

$ sudo vi /etc/ssh/sshd_config

Be sure to locate these two parameters: ClientAliveInterval and ClientAliveCountMax. Let’s check out what they do.

  • ClientAliveInterval – This is the period of inactivity after which the SSH server sends an alive message to the remote client that is connected to it.
  • ClientAliveCountMax – This is the number of attempts that the server will make to send the alive message from the server to the client.

We will set the two values as follows:

ClientAliveInterval	300
ClientAliveCountMax	3
Configure SSH Timeout Interval
Configure SSH Timeout Interval

This means that after the first 300 seconds (5 minutes) of inactivity from the client, the server will send an alive message to the client to keep the SSH session active.

If no data or response is received from the client for the next 300 seconds (at the 600-second mark), the server will again send another alive message. Finally, after 900 seconds of inactivity from the client, the SSH connection will be terminated or dropped.

Be sure to save the changes made to the file and then exit. Then restart the SSH daemon.

$ sudo systemctl restart sshd

Alternatively, you can connect to your remote client Linux system by specifying the ServerAliveInterval parameter in seconds (300 seconds), which means your SSH session is active for up to 5 minutes.

$ ssh -o ServerAliveInterval=300 username@server_ip_address
Keep SSH Session Alive
Keep SSH Session Alive

In this tutorial, we demonstrated how to resolve the Client_loop: send disconnect: Broken pipe error. As you have seen all you need is to perform a few tweaks in the SSH configuration file.

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

2 thoughts on “How to Fix SSH Client_loop: send disconnect: Broken pipe Error”

  1. Does “TCPKeepAlive yes” in the ssh_config file have any additional effect? I have seen recommendations to use that as well.

    I’ve been fooling with this issue for a few days after I updated my Ubuntu 22.04 work machine. I use that machine to ssh to my webserver and firewall. Previously my ssh connections inside my network were permanent and they began timing out. I do not know yet whether I have solved the problem.

    • @Wastrel,

      Yes, setting ‘TCPKeepAlive yes‘ in the ssh_config file can have an impact on maintaining SSH connections. When enabled, it sends TCP keepalive messages to prevent the connection from being terminated due to inactivity.


Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.