Stop/Prevent SSH Timeouts
June 5th, 2008
I use ssh quite a bit and am extremely annoyed when my shell session times out after a certain period of inactivity, say 20 minutes - what a hassle! Then you have to log back in, open up your files again, try to remember what you were working on, etc. To make a long story short, ssh timeouts cause a lot of headache and so I’ve taken the time to find out how to stop it from happening. The ssh timeout problem doesn’t come from the ssh deamon you are working with but rather…
the problem is actually not usually due to SSH, but rather to an intervening network device, often a NAT gateway or firewall. These devices keep track of TCP flows and time them out after a period of inactivity, for reasons of security or resource consumption. OpenSSH does not have an idle-timeout feature. SSH1, Tectia, and VShell do, but the feature is off by default.
So the problem is not your SSH client but it’s some crappy router or network device in between your computer and the server you work on that kicks you off. Sounds a bit unfair doesn’t it? Damn straight, let’s fix it. To keep your SSH client from timing out, you will need to open up the
/etc/ssh/sshd_config
file and insert the following two lines (in some linux distributions they are already there so in that case you just need to uncomment the lines and change the int values):
ClientAliveInterval 30
ClientAliveCountMax 4
you will need to restart your ssh deamon by doing something like this:
/etc/init.d/sshd restart
Once that is done, any future shell sessions you start shouldn’t timeout anymore!




Leave a Reply