Prevent SSH Connection Timing Out / Broken Pipe

How to prevent an SSH session from disconnecting to a server. Connection Timed Out or Broken Pipe

Both as a user of Windows as well as by Mac (in the last 10 years) I spent a lot of time in SSH connections to web servers, email servers, cloud and other backup packages. Linux's preferred distribution is undoubtedly CentOS.

One of the most stressful things for server administrators is to interrupt SSH connections. Either suddenly while buttoning in Putty or Terminal (most often being a local connection issue), or after a while of "idle”- the period of time in which it does not interact with the remote server through the SSH session.

If you are using the Mac and use the Terminal utility for the remote connection via SSH, then you have certainly been disconnected with the message:client_loop: send disconnect: Broken pipe”. I gave the solution in the article here, in which I said that it can be added in "/etc/ssh/ssh_config" the line:

Host *
ServerAliveInterval 120

The above solution is valid for users of Mac, and honestly to be the latest updates of macOS I don't mind restart changes made to the file "ssh_config", And the problem with disconnecting an idle session returns.

A solution by which we can prevent the disconnection of an SSH session at a distance set by Port (macOS) or Putty (Windows), is like besides “ServerAliveInterval”From our computer, to determine the remote server to communicate periodically with the SSH application / client.
That's why we have to put the directive "ClientAliveInterval"In"sshd_config”On the server we are connecting 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 interval for "ClientAliveInternal". We open SSH in Putty, Terminal or other similar utility and we authenticate with the user root.

ssh [email protected]

2. Execute the command line to search the "sshd_config" file if "ClientAliveInterval" is active and what time period is set.

sudo grep "ClientAliveInterval" /etc/ssh/sshd_config

In our scenario "ClientAliveInterval" is disabled and the time interval value is zero.

[[email protected] ~]# sudo grep "ClientAliveInterval" /etc/ssh/sshd_config
#ClientAliveInterval 0
[[email protected] ~]# 

The hashtag "#"Placed in front of a line, cancels it. She is inactive.

3. We open with the editor "nano"Or"vim"File"sshd_config“. I prefer "nano".

sudo nano /etc/ssh/sshd_config

4. Delete “#"In front of the line"ClientAliveInterval”And set a number of seconds: 60, 120…

ClientAliveInterval 120
ClientAliveCountMax 10

5. Save the changes and restartI have the service "sshd".

sudo systemctl restart sshd

ClientAliveInterval : It is the time interval in seconds that the server sends a null data packet to the client / application through which we are connected to the server. This practice will keep the connection alive / active.

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

With these changes the SSH connection will be more stable and remain just as secure.

Leave a Reply

your email address will not be published. Required fields are marked *

Previous Article

How do we see what users are looking for on a WordPress site or WooCommerce online store (Search Box Query)

Next Article

Can't hear the "Empty Recycle Bin" sound anymore? [How To Fix]