Prevent SSH from disconnecting

Anyone who has worked with a remote Linux server using SSH must have faced the problem of having the SSH session drop dead when you head out to get a cup of coffee. Well, here’s a solution to help you configure your SSH daemon on the Linux server to stop it from disconnecting. What happens is that if you leave your SSH connection on and don’t use it for some time the SSH server goes into an idle mode and kills the session. This is really a security measure which can sometimes be a little annoying.

To set this up log on to your remote Linux server using SSH. Open the SSH configuration file:

# vim /etc/ssh/ssh_config

Add the following line at the end of the file:

ServerAliveInterval 60

Save the file and quit the text editor. Now, similarly, open the file ~/.ssh/config. Create the file if it does not already exist. Add the following lines:

Host *
ServerAliveInterval 60

Note: you need to indent the second line by entering a space at the beginning of the line.

You’re all done now. Time to restart your SSH server. Run the following command:

# /etc/init.d/sshd restart

This should take a second or two. Then you should be back in business. What we have done here is that we have pretty much fooled the SSH server into thinking that your SSH session is active even when it’s not. Now you can peacefully take a short coffee break without losing your SSH connection.


I am a g33k, Linux blogger, developer, student and Tech Writer for My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.