Preventing ssh disconnections occuring due to time out

If you are getting connection drop outs after a certain idle time while connected to an ssh server, this is probably due to some short time out periods set in the server’s configuration. That’s easy to solve, unless the problem stems from another network issue. When connecting next time, if you set the following ssh options, you shouldn’t be getting disconnected automatically anymore:

ssh -o TCPKeepAlive=no -o ServerAliveInterval=30 your_user_name@some_domain.com

You may either change your ssh client’s config to make these options permanent, or set an ssh name alias under your .bashrc in Linux:

alias ssh=’ssh -o TCPKeepAlive=no -o ServerAliveInterval=30′;

This way, you won’t have to specify these options again. Just start a new terminal or “source” your .bashrc after making this change:

source /path/to/.bashrc

This solution has the benefit of not requiring any configuration change on the server side, which is handy, because you may not have a permission to make any change on the server side.

Alternatively, if you have access to the server configuration, then you can add these lines to your server’s /etc/ssh/sshd_config file:

ClientAliveInterval 30
TCPKeepAlive yes
ClientAliveCountMax 99999

To activate the new settings you will need to restart your ssh server.