Secure shell (ssh) session timeout

I’ve noticed that when I keep ssh sessions that I opened before untouched for some period of time (like 30 minutes) they become frozen and as a result I have to close ssh terminal and start a new connection. To prevent such situation I found several tips:

1) Start some utility updating the screen before leaving ssh session untouched. I usually use watch -n 1 ‘date’ that shows current date every second. Other simple way is to send icmp requests to some host, e.g. ping

2) Increase ssh session idle time by

echo “7200” > /proc/sys/net/ipv4/tcp_keepalive_time

I’ve checked these tips with Fedora Core, CentOS, Debian and Ubuntu but I’m completely sure that it applicable also for other Linux distributions. First tip (ping) can be used in Unix also.

You may also be interested in:
Secure shell (ssh) connection without password
Keep ssh session saved (Unix “screen” utility)
Moving Linux to remote server (over ssh via third server)


Stefan Durand

My name is Stefan, I'm the admin of LinuxScrew. I am a full-time Linux/Unix sysadmin, a hobby Python programmer, and a part-time blogger. I post useful guides, tips, and tutorials on common Linux and Programming issues. Feel free to reach out in the comment section.

1 thought on “Secure shell (ssh) session timeout”

  1. I've been trying to deal with the freezing of ssh sessions on a debian etch box (kernel:2.6.18-5-686) for a while and have not had much luck.

    Sessions freeze after just a few minutes of inactivity – even if I am sitting in pine.

    echo "7200" > /proc/sys/net/ipv4/tcp_keepalive_time

    did not make any difference. Actually, 7200 was already stored in that file.

    This is a new problem which I did not have before upgrading from Mandrake 10 to Debian.

    Under Mandrake, idle sessions would get logged off (as opposed to frozen) after a reasonable interval.

    Can you suggest other things that I could try?



Leave a Reply

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