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

 

Advertisements

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


  1. 1 Ben August 31, 2008 at 2:40 am

    Another good way that only applies if you own the box you are SSHing to:

    ClientAliveInterval
    Sets a timeout interval in seconds after which if no data has been received from the client, sshd will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client. This option applies to protocol version 2 only.

    My SSH server has ClientAliveInterval 300, which sends a packet every 5 minutes 🙂
    I’m pretty sure there is a client setting that does something like that.
    Just thinking about running the same command over and over, every second, makes me sad. All the cycles that get wasted.

  2. 2 tom September 1, 2008 at 10:22 am

    the client setting is:

    ServerAliveInterval

    I have the following in ~/.ssh/config

    Host *
    […]
    ServerAliveInterval 300
    […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Archive


%d bloggers like this: