Skip to content

Keep SSH Sessions Alive

In some servers that I access through SSH, I keep having my SSH sessions get dropped after being idle for some time.

A straightforward fix for this is to enable SSH keepalives. You can set this through SSH's ServerAliveInterval option.

Set keepalive through SSH command line option

ssh -o "ServerAliveInterval 60" [email protected]

This command will set the ServerAliveInterval option to 60 seconds for the SSH session.

Set keepalive for all SSH sessions

To set a keepalive value for all your SSH sessions, you can add the following in your system's /etc/ssh/ssh_config file or your user's ~/.ssh/config file.

ServerAliveInterval 60

Set keepalive for PuTTY

For PuTTY, you can set the following:

  1. In PuTTY's configuration window, go to the Connection section.
  2. Set Seconds between keepalives to your desired value.

Further Reading

You can check ssh_config's manual page for more information on other SSH client configuration.