What exactly causes a ssh connection to interrupt? When you idle for a while, it disconnects.

How do I keep the connection alive (without autossh or reconnect)?

2 Answers 2


This is most likely a firewall which cuts your idle connection after a while.

You can configure the openssh server or client to send a KeepAlive after a while.

Send a KeepAlive every 5 minutes to the server:

ssh user@server -o ServerAliveInterval=300

If you have control over the openssh-server, you can also send KeepAlives to the client after a defined interval. Add the following to /etc/ssh/sshd_config:

ClientAliveInterval 300
TCPKeepAlive yes

TCPKeepAlive should be yes by default.

Restart the openssh-server after the modification:

/etc/init.d/ssh restart

Here are a few things you can try:

1) It's most likely the shell which is timing out. Disable the timeout by unsetting TMOUT in your profile. TMOUT is the number of seconds that bash waits for input before terminating. Echo $TMOUT to see if it is set. Add the following to your profile:

unset TMOUT

2) Configure PuTTY to send keepalive packets by going into:

Settings > Connection > Seconds between keepalives = 60

3) Tweak your sshd_config (normally found in /etc/ssh) and add:

TCPKeepAlive yes
ClientAliveInterval 60

Save the file and restart sshd.

  • in theory this should always make the connection established? i will try ClientAliveInterval
    – c2h2
    Commented Jan 19, 2011 at 17:53
  • This works great!!!! havn't disconnected for 24 hours, where normally breaks every hour.
    – c2h2
    Commented Jan 20, 2011 at 9:34
  • Adding ClientAliveCountMax 1440 will allow the connection to time out after 1440 minute checks (1 day). You can adjust this to extend the timeout but not disable it completely. Commented Nov 21, 2019 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .