Keeping Your ssh Connection Alive
![]() |
You can fix this using the SSH config option ServerAliveInterval. SSH options can be set on the command-line (with the -o option), or by editing your ~/.ssh/config or /etc/ssh_config files. Note that SSH uses the first setting that it encounters for an option, and it reads command-line options, then per-user config, then the global config, and general/default ones at the end.
Add this to your ~/.ssh/config file to turn ServerAliveInterval on for all SSH connections:
Host * Protocol 2 ServerAliveInterval 60 |
ServerAliveInterval sends a package through the encrypted channel, after the specified number of seconds of inactivity, to the server, requesting a response. It's turned off by default, and you may need to experiment a little with the value. However, once you have the value set to work with your system, you should be able to keep your SSH sessions connected.
Note: Most systems will have TCPKeepAlive on by default. This sends a TCP package after a period of idleness, usually two hours. This is often too long an interval to prevent disconnection; and TCPKeepAlive packets can also be spoofed, unlike ServerAliveInterval.




Windows Server 2008 R2 provides enhanced management control over resources across the enterprise. Downlaod this PDF to learn more.