OpenSSH - Connection drop / Broken Pipe
Are you experiencing connection loss or 'Broken Pipe' messages when using SSH to connect to your VPS? In this guide i will explain how to change the SSH settings so that you are able to idle longer without getting a connection loss.
Edit the OpenSSH configuration file
Start by connecting via SSH to your VPS. Edit your OpenSSH configuration file
nano /etc/ssh/sshd_config
Scroll down in the file and find the settings: ClientAliveInterval and ClientAliveCountMax
The ClientAliveInterval (in seconds) is a timer that waits until it reaches zero (0). When it reaches zero it will send a null packet to the VPS that the connection may be terminated.
The ClientAliveCountMax counts how many times the ClientAliveInterval has been reached. When it reaches the value it currently has, the connection will be terminated.
By increasing the values of both, we are able to be longer inactive while the SSH connection stays alive. By default the ClientAliveInterval is at 0 and the ClientAliveCountMax at 3.
Let's start by setting the following values:
ClientAliveInterval 300
ClientAliveCountMax 6
(Do not forget to remove the hashtags before the values (#))
Save & exit the sshd_config
file.
The last step is to restart the OpenSSH service, do this by executing the following command:
service sshd restart
You have now increased the inactivity timers for SSH. Your connection should stay alive longer while idling.