Keeping SSH Connections Alive

Date December 16, 2007 by Isaac

There are times that you need to maintain a long-term SSH connection. This may be because you need to keep a tunnel open, or you just want to stay logged into a machine. However, depending on the settings and network conditions of all the intervening computers it may be difficult to keep this connection open. If a connection goes idle for a period of time then a computer might decide to close your SSH connection.

Fortunately, SSH has many settings, including some to keep connections open. One of these settings, which is not recommended, is TCP Keep Alive. I am not a network hacker, so all I know is that this is bad. This method can be spoofed.

The preferred method to keep a SSH connection open is to use the ServerAliveInterval option. To use this you would do:

ssh -o TCPKeepAlive=no -o ServerAliveInterval=15
 

This would disable the TCPKeepAlive setting and send an encrypted packet once every 15 seconds. By sending this packet every 15 seconds it will (hopefully) stop the computer from timing out and closing the connection. Of course 15 seconds is probably a bit too often, but that depends on the specifics of your connection. You want this often enough to keep the connection open, but too often and you generate unnecessary traffic.

References

SSH connection stability

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>