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: sinology


Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   heberth squirrel said

    good contribution…

  2.   Gaspar Fernandez said

    Go just four days ago I wrote something very similar on my blog. Good idea about the autossh: http://totaki.com/poesiabinaria/2012/08/solucionar-problema-con-timeouts-y-broken-pipes-con-ssh-y-scp/

  3.   Simon said

    The source for this article is old because "Keepalive" no longer exists as an SSH configuration parameter.

  4.   nacho said

    Any ssh client for android that you recommend?

  5.   nacho said

    Do you recommend any ssh client for android?

  6.   crafty said

    Could it be that the file is called ssh_config and not sshd_config?

  7.   Faith Diaz said

    and if you still can't avoid crashing because you're on a bad connection or something like that, log in and use screen to unlink your session PID with your connection PID.

  8.   dismestres3 said

    Good contribution!

    If you do not have access to the SSH server, you can implement it on the client side, with Putty or desde Linux.

    With putty:

    "Connection", "Sending of null packets to keep session active", "Seconds between keepalives" and enter a number.

    Also mark the option:

    "Enable TCP keepalives (SO_KEEPALIVE option).

    Source: http://www.sysadmit.com/2016/02/linux-y-vmware-ssh-evitar-desconexion.html