HOWTO: Set the SSHD Idle Timeout
Here’s something that I usually forget to change from the default and then get annoyed when my terminal hangs.
- As root open your sshd_config file in an editor.
su -
vim /etc/ssh/sshd_config - Add the following lines.
ClientAliveInterval 600
ClientAliveCountMax 3 - Restart the sshd process.
service sshd restart
That’s it. That will keep you logged in for 30 minutes at a time without activity. (600 seconds x 3)
Jordan Lev
Thanks for this helpful post! I was having lots of trouble getting this to work for larger amounts of time (30-60 minutes) because I thought these were the settings for the actual timeout limit of the sshd sessions so I was setting the ClientAliveInterval to a very high value (3600 for an hour). BUT I didn’t understand that this isn’t changing the timeout limit — those are set elsewhere (not sure where, but it doesn’t matter) and seem to be 15 minutes on my Ubuntu Hardy system. What these ClientAlive___ settings do send a packet back and forth to the client every so often to keep the connection alive, so you must set the ClientAliveInterval to a number that is LOWER than whatever the built-in timeout is (so in my case, less than 900 [900 seconds=15 minutes]), then set the ClientAliveCountMax to the number of times you want that packet sent. So what worked for me to keep the session alive for an hour was to set both to 60 — send the packet every 60 seconds, and do that 60 times. Phew!