For those that need to work constantly on SSH, it can be very frustrating when the system cut you off after a period of time. This article shows you the method to keep SSH connection alive until you disconnect it.
Login to your remote system, or open the terminal in your own computer.
Open the /etc/ssh/ssh_config file.
sudo nano /etc/ssh/ssh_config
and add the following line to the end of the file:
ServerAliveInterval 60
What this option does is to send a null packet to the server at every 60 seconds (of inactivity) to keep the SSH connection alive. You can experiment with the value, setting it to either higher or lower, depending on your system configuration. A value of 60 is a good starting point to start the experimentation.
Per user configuration
If you don’t have root access to the system or you just want to configure it for your personal account, you can edit the ~/.ssh/config file instead.
sudo nano ~/.ssh/config
If the file does not exist, this will create a new file.
Add the following line:
Host * ServerAliveInterval 60
Press “Ctrl + o” to save and “Ctrl + x” to exit.
Lastly, restart the SSH server.
sudo service ssh restart
That’s it.
Damien Oh started writing tech articles since 2007 and has over 10 years of experience in the tech industry. He is proficient in Windows, Linux, Mac, Android and iOS, and worked as a part time WordPress Developer. He is currently the owner and Editor-in-Chief of Make Tech Easier.
Subscribe to our newsletter!
Our latest tutorials delivered straight to your inbox
Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe