Keep SSH session alive

Surely I’m a geek who likes keeping multiple ssh connections opened, thus I had realize that these connections were closed automatically when I was idle after a while and I get tired of this issue, so after a large searching on google I had notice that the problem was lying on the .ssh/config file, which it was not defined any rule that allow keeping alive ssh connection to my server.

Therefore, you can configure ssh client sends a ping to the server in order to avoid disconnect after a while of idle. This setting is known as Keep-Alive or Stop-Disconnecting or something-else in other clients.

Config server side

Add or modify the following sentence to the /etc/ssh/ssh_config:

ServerAliveInterval 60  

where 60 is the amount of seconds before the server will send a ping command.

Configuration in client side

Create the config file (if does not exist) and add the following lines to ~/.ssh/config

Host *  
    ServerAliveInterval 60

Consider indent line with 4 spaces normally, and the asterisk mark is a wildcard that means all servers are affected by this rule, if you want to apply this one to one specific server, only you have to do is typing server’s hostname instead of wildcard.

After that, it’ll work well and I hope it helps somebody else out there.

Leave a Reply