How to Solve SSH Broken Pipe Error in Linux

How to Solve SSH Broken Pipe Error in Linux

Nowadays, connecting to a remote server and doing various tasks is common. SSH is one of the best protocols that is used to have a remote connection. In spite of SSH benefits, an error might occur and end the connection. In this article, you will learn How to Solve SSH Broken Pipe Error in Linux. Network administrators and IT professionals try to keep the remote connection stable, secure, and uninterrupted to prevent terminating an SSH session unexpectedly. Buying Linux VPS is the first step to using SSH to establish secure connections to remote systems. However, it is important to know about potential errors and their solutions.

Due to various reasons, the SSH broken pipe error occurs and disconnects you from the remote server. First, we will explain more about the Linux SSH Broken Pipe Error and the reasons it occurs. Then, 4 quick methods to solve SSH Broken Pipe Error will help you know what to do after viewing this error when you are in a remote connection. This helps to not initiate the connection repeatedly. Since SSH Broken Pipe Error has been reported on all Linux distributions, join us to learn How to Solve SSH Broken Pipe Error in Ubuntu, Debian, and CentOS.

SSH Broken Pipe Error in Simple Words

To connect to a remote server, secure transmission protocols help us to have an uninterrupted and secure connection. SSH protocol is one of the most popular ones that asks for the remote IP and the username of the machine it is going to connect. Before knowing about the causes of this error and preventing that, let’s know What is SSH Broken Pipe Error. This error indicates that data was being sent from the SSH client to the server, but the connection was broken before the server could confirm receipt of the data. displaying this error also means that the client and server’s TCP connection has been broken, preventing them from connecting.

What Causes Linux SSH Broken Pipe Error and How to Prevent It

In fact, there are some main reasons for the SSH Broken Pipe error in Linux. Now that you know what this error is, let’s review the causes that help to solve SSH Broken Pipe Error. Network Issues, Client issues, and Server Timeouts are the primary reasons of occurring this error. Here, we explain more:

  • Network Issues: This can be a problem with a firewall or proxy server, an unstable or lost internet connection, or both.
  • Client Issues: This error may occur if your SSH client shuts down unexpectedly or crashes.
  • Server Timeouts: To save resources, many servers are set up to terminate standing connections after a predetermined period of time. Your SSH client’s connection might be dropped and a broken pipe error might result if it is inactive for longer than the server’s timeout setting allows.

When using SSH to connect to remote Linux servers, you may discover that if your SSH session is dormant for a while, and then you try to use it again, it disconnects and displays an error message similar to this:

:client_loop: send disconnect: Broken pipe

‘Write failed: Broken pipe’ or ‘Connection closed by remote host’ may be displayed on some systems.

The ClientAliveInterval and ClientAliveCountMax metrics should be taken into consideration when preventing the SSH broken pipe. The maximum number of cycles a connection will remain active before being cut off if the SSH client becomes unresponsive is known as ClientAliveCountMax. The ClientAliveInterval is the number of seconds it takes for the server to deliver a connected client null data packets in order to maintain the connection.

Quick Methods to Solve SSH Broken Pipe Error in Linux

Let’s go through this guide and review the most efficient solutions to prevent SSH Broken Pipe Error in Linux Ubuntu, Debian, CentOS, etc. The objective is to maintain the connection between the client and the server by modifying various metrics in the client’s and server’s SSH configuration files.

Check out the below solutions and try to do them on your server to avoid the SSH Broken Pipe Error in Linux ubuntu.

1. Actively Maintain Your Session

When servers are left idle for too long, connections are frequently lost. You can prevent this by keeping your session open. You can accomplish this by periodically running commands in the SSH client. As a Linux administrator, you can also monitor Active SSH Connections in Linux.

2. Start Using a Terminal Multiplexer to Prevent Linux SSH Broken Pipe Error

You can maintain sessions running even if your connection is lost by using tools like ‘screen’ or ‘tmux’. These programs establish persistent sessions, which carry on after your SSH connection is cut off. You can carry on from where you left off after you’ve reconnected.

3. Start Using a VPN or trustworthy network

Since a VPN can offer a more dependable, secure connection, you are recommended to consider utilizing a VPN or changing to a more dependable network if your network is unreliable or prone to outages.

4. Configure Server and Client Settings

One of the most efficient ways to solve SSH Broken Pipe error is to configure the SSH Server and Client that seriously prevent disconnections due to inactivity.

On the Server Side:

The config file is usually located in the /etc/ssh/sshd_config on the server side and has the ClientAliveInterval and the ClientAliveCountMax metrics. Configuring this file is helpful in preventing the SSH broken pipe error.

ClientAliveInterval 120
ClientAliveCountMax 720

If you set your ClientAliveInterval to 60 seconds and your ClientAliveCountMax to 2, the server will send the alive messages twice every 60 seconds. Following that, it displays an SSH broken pipe error. Open the config file and set your preferred parameters to prevent occurring the error.

To not face the error again, save your file and exit.

On the Client Side:

As you guessed, the configuration must also be done on the client side to complete this method to solve SSH Broken Pipe error.

You can specify how long an SSH connection should be kept alive before being disconnected. This increases the ServerAliveInterval. You can change it when you make an SSH connection or when you create a config file on the client side. To avoid the SSH broken pipe in Ubuntu, use the following command when connecting over SSH:

ssh -o ServerAliveInterval=300 username@server_ip

You can also create an SSH configuration file by running the command below:

touch ~/.ssh/config

Use the following command to change the permissions of its file after creating the SSH configuration.

chmod 600 ~/.ssh/config

Then, echo the preferred ServerAliveInterval:

echo “ServerAliveInterval 300” >> ~/.ssh/config

The above steps prevent the SSH broken pipe error in Linux.


In this article, you learned How to Solve SSH Broken Pipe Error in Ubuntu, Debian, and CentOS. Since the SSH broken pipe error happens when the client fails to receive answers, causing the connection to disconnect, you can avoid this by modifying the ClientAliveInterval and ClientAliveCountMax settings on the server. You can still use the ServerAliveInterval metric while connecting over SSH, or build an SSH config file on the client and include the ServerAliveInterval. Facing such an error or SSH “Connection Refused” might bother IT professionals and Network administrators.

However, if you do the suggested solutions in this guide, you can smoothly fix SSH Broken Pipe Error in Linux but do not hesitate to contact us if you encounter any problems. Our technical support team will try their best to solve your problems.

Leave a Reply

Your email address will not be published. Required fields are marked.