Prevent SSH Connection Timing Out / Broken Pipe

This tutorial offers you a very good solution if you use SSH connections and meet the error: SSH Connection Timing Out / Broken Pipe. Improperly said error. It is a message announcing that the connection between your computer and the server to which it was connected by Putty or Terminal.

Both as a Windows and Mac user (over the past 10 years) I spent a lot of time in SSH connections At the web servers, e-mail servers, cloud and other backup balars. Linux's favorite distribution is undoubtedly CentOS.

One of the most stressful things for server administrators is to interrupt SSH connections. Either suddenly while buttons in putty or Terminal (most often being a local connection problem) or after a time of “idle” – The time period in which it does not interact with the remote server through the SSH session.

If you are a poppy user and use the terminal equipment for the distance connection via SSH, then surely after inactivity you have been disconnected with the message: "client_loop: send disconnect: Broken pipe”. The resolution I gave it in The article here, in which I said it can be added in “/etc/ssh/ssh_config” line:

Host *
ServerAliveInterval 120

The above solution is valid for Mac users, and honestly to be the latest Macos updates do not retain after restart the changes made in the file “ssh_config“, and the problem with disconnecting a session in idle returns.

A solution through which we can prevent off disconnecting a SSH session at a distance established by Terminal (macos) or Putty (Windows), is like beside “ServerAliveInterval” From our computer, to determine the remote server to communicate periodically with the SSH application / client.
For this we have to put the directive “ClientAliveInterval” in “sshd_config” on the server we connect to.

Prevent SSH Connection Timing Out / Broken Pipe (ssh_config Tips)

1. We connect to the server we want to activate and set a time range for “ClientAliveInternal“. open SSH in Putty, Terminal or another similar utility and we authenticate with user root.

ssh root@server.hostname

2. We execute the command line to search in the file “sshd_config” daca “ClientAliveInterval” It is active and what is the set time set.

sudo grep "ClientAliveInterval" /etc/ssh/sshd_config

In our scenario “ClientAliveInterval” It is deactivated and value of the time interval is zero.

[root@buffy ~]# sudo grep "ClientAliveInterval" /etc/ssh/sshd_config
#ClientAliveInterval 0
[root@buffy ~]# 

Semnul hashtag “#” Put in front of a line, cancel it. It is indifferent.

3. We open with editor “nano” or “vim” FILE “sshd_config“. I prefer “nano“.

sudo nano /etc/ssh/sshd_config

4. We delete “#” in front of the line “ClientAliveInterval” and we set a number of seconds: 60, 120 …

ClientAliveInterval 120
ClientAliveCountMax 10

5. We save the changes and restart the service “sshd“.

sudo systemctl restart sshd

ClientAliveInterval : It is the time interval in seconds at which the server as sends a null data pack to the client / application by which we are connected to the server. This practice will keep your connection in life / active.

ClientAliveCountMax : SSH clients who do not answer in 10 cycles of 120 seconds (set by “ClientAliveInterval“) the connection will be interrupted. That is, after 20 minutes in which client SSH did not respond to the null package sent by the server.

With these changes the connection SSH It will be more stable and remains as safe.

Passionate about technology, I write with pleasure on stealthsetts.com starting with 2006. I have a rich experience in operating systems: Macos, Windows and Linux, but also in programming languages ​​and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, Presashop).

Home Your source of IT tutorials, useful tips and news. Prevent SSH Connection Timing Out / Broken Pipe
Leave a Comment