How to Fix ‘client_loop: send disconnect: Broken pipe’ in SSH

In this tutorial, you'll learn what to do when your SSH connection times out with the errors 'client_loop: send disconnect: Broken pipe' or 'client_loop: send disconnect: Connection reset.'

These errors indicate a disconnected SSH connection and are most likely caused by your home router.

It can be fixed from either the server side or the client side. We will address both.

Server-Side Fix

To resolve the broken pipe and connection reset errors from the SSH server, you can adjust the values of the ClientAliveInterval and ClientAliveCountMax settings.

You can find these settings in the /etc/ssh/sshd_config file. ClientAliveInterval specifies the time (in seconds) the SSH server waits before sending a message to the client to keep the connection alive. ClientAliveCountMax specifies the number of times these messages are sent to the client before the connection is terminated.

My suggestion is to set the ClientAliveInterval to a lower value, such as 30 or 60 seconds, and then increase the value of ClientAliveCountMax to a very high number according to your needs.

ClientAliveInterval 60
ClientAliveCountMax 1000

Once you've changed these settings, restart the SSH server:

systemctl restart ssh.service

Client-Side Fix

If you don't have permission to configure the SSH server, you can still resolve these errors by adjusting the ServerAliveInterval and ServerAliveCountMax settings on your local computer.

There are two ways to do this. The first is to specify the ServerAliveInterval and ServerAliveCountMax settings in the ssh command, as shown in the following example:

ssh [email protected] -o ServerAliveInterval=60 -o ServerAlivecountMax=10000

The second method is to make these settings permanent by adding them to a client-side configuration file.

Linux Client Configuration

For Linux users, the client-side configuration file is located at /etc/ssh/ssh_config (not sshd_config). In this file, you'll set values for ServerAliveInterval and ServerAliveCountMax as shown in the following example:

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 10000

Windows Client Configuration

If you're using the ssh command on Windows, you'll find a folder named .ssh in your home directory. Inside this folder, create a file named config (without any extension) and add the following configuration lines:

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 10000

Conclusion

Okay, this concludes our troubleshooting guide on how to fix 'client_loop: send disconnect: Broken pipe' or 'client_loop: send disconnect: Connection reset' errors that disconnect your SSH connections to remote servers. Hope this was helpful!

This happened on an AWS EC2 instance
This happened on an AWS EC2 instance.
sshd_config
sshd_config
restart the SSH server.
Don't forget to restart the SSH server.
SSH client configuration file on Linux
SSH client configuration file on Linux.
SSH client configuration file on Windows.
SSH client configuration file on Windows.
Client-side configuration.
Client-side configuration.