Keeping SSH Sessions Alive February 3, 2006Posted by Carthik in administration, snippets, ubuntu.
Scott Merrill writes in to say:
I noticed recently that ssh connections from my Ubuntu laptop to my
Debian server would time out and disconnect if I left the connection
idle for a long-ish period of time. This really annoyed me, because my
Debian desktop does not exhibit this behavior when connecting to the server.
I added the following line to
That seems to have fixed the problem, and my laptop can now remain
connected, though idle, to my server. Maybe this will help someone
What this does, essentially is every 5 seconds, the client sends a small keep-alive packet to the server to make it look like the ssh connection is being actively used. The reason for Scott’s timeout could be a NAT firewall that seeks to minimize the nember of active connections to reduce its memory footprint, or to improve performance for other clients. Most firewalls and networks let you keep your connections alive for as long as you wish, but some may act up, and that’s when you can use Scott’s trick.
Tip: Change 5 to 240 or 300, so that instead of every 5 seconds, the keep-alive signal is sent only once in 4 or 5 minutes :)
Sorry it took me so long to post this useful tip, Scott.