Secure shell (ssh) session timeout

Welcome to Linux Screw! If you're new here, you may want to subscribe our RSS feed.

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 google.com.

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)

 
 
» You might also be interested in the following articles:
Local and remote X sessions on different consoles
Quick shell change for user in Unix or Linux
Site of the day: Free Linux eBooks
Can’t find usable shell script encryption solution…
Automatic "zombie" processes killing (shell script)



» Want to stay up to date? Subscribe to our E-MAIL or RSS feed!


2 Responses to “Secure shell (ssh) session timeout”


  1. 1 P.E.

    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?

    Thanks!

    P.E.

  2. 2 artiomix

    Hi P.E.,

    Here are some directives of SSH server’s sshd_config that are related to session timeouts:

    ClientAliveInterval
    TCPKeepAlive
    KeepAlive

    Here are some directives of client’s ssh_config:

    ServerAliveInterval
    TCPKeepAlive

    sshd_config and ssh_config are usually located at /etc/ssh directory of server and client.

    These directives are are widely described by man sshd_config and man ssh_config but default settings may be different from distro to distro.

    P.S. As for me, I found first tip of current post the most useful as it works brilliantly at every *nix machines I was working with via ssh (just make ping 127.0.0.1 when you’re going to leave ssh terminal untouched for some time).

    P.P.S. Another nice workaround is to use screen utility. In case you use it you can be sure that you won’t loose any output of commands you’ve started. Here is little notice how to use it.

    Good luck!

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word




Friendly Sites:Who is behind Linux Screw?
Aspiring Sysadmin | GeekyBits³ | Bash Cures Cancer | TOTMS
Linux Operating System | Small Linux Deployments | My SysAd Blog
The Danesh Project | ZEPY | Linux config Wiki | Planet Sysadmin
The Sys Admin | {buhay sysad} | a non-geek's linux notes
Linux HOWTOs, Tutorials & Projects with Adam Palmer | LinuxAlt.Com
My name is Artem Nosulchik (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››