How to keep SSH connections alive

If you are an administrator and you use SSH To connect with other systems, it will have happened to you more than once that after a while the connection drops and you have to reconnect, with the consequent loss of information.


This "trick" is well known to any system administrator, but perhaps some of you do not know it.

The idea is that the server forces the client to send a packet to keep the connection open (which is usually known as keep-alive) and is configured on the SSH server to which we connect by modifying the / etc / ssh / sshd_config file and adding these two lines to the ssh daemon configuration:

TCPKeepAlive yes
ClientAlive Interval 60

With this, we only have to quietly restart the ssh daemon and when connecting, we can leave the session open without fear of being disconnected.

Another possible option is to use a tool called autossh. To install it in Ubuntu and derivatives, just run:

sudo apt-get install autossh

In the case that we want to use it in a simple way, we could already execute:

autossh remote_user @ remote_host

Source: Sinologic


Add as preferred source in Google