Prevent SSH Connection Timing Out / Broken Pipe

This tutorial offers you a very good solution if you use SSH connections and encounter 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 it was connected to was closed Putty or Terminal.

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. Favorite distribution of Linux is undoubtedly CentOS.

One of the most stressful things to do administratorii server is to interrupt SSH connections. Either suddenly while buttoning in Putty or Terminal (most often it is a local connection problem), or after a time 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 utility Terminal for the remote connection via SSH, then surely after some inactivity you were 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 do not retain the changes made in the file after restartssh_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 Terminal (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". open SSH in Putty, Terminal or another similar utility and we authenticate with user root.

ssh root@server.hostname

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

sudo grep "ClientAliveInterval" /etc/ssh/sshd_config

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

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

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 restart 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 customer SSH did not respond to null packets sent by the server.

With these changes the connection SSH it will be more stable and remain as safe.

Passionate about technology, I enjoy writing on StealthSettings.com since 2006. I have a rich experience in operating systems: macOS, Windows, and Linux, as well as in programming languages and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, PrestaShop).

How to » Linux » Prevent SSH Connection Timing Out / Broken Pipe
Leave a Comment