How to keep SSH conections alive on Linux
Set up on client side
To enable the keep alive option system-wide (root access required), you should edit the file /etc/ssh/ssh_config and add these options:
Host *
ServerAliveInterval 300
ServerAliveCountMax 3
You can also set the settings for just your user, editing the file (or create it if it doesn’t exist) ~/.ssh/config , the options are exactly the same.
Set up on server side
You can make your OpenSSH server keep alive all connections with clients by adding the following to the file /etc/ssh/sshd_config:
ServerAliveInterval 300
ServerAliveCountMax 3
With these settings will make the SSH client or server send a null packet to the other side every 300 seconds (5 minutes), and give up if it doesn’t receive any response after 3 tries, at which point the connection is likely to have been discarded anyway.
Written by Renato Vasconcellos Gomes
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ssh
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#