Friday, May 09, 2014

Linux - How to Keep SSH Connections Alive in Linux

If you want to work constantly on SSH, it can be very frustrated when you session gets cut off after some period of time. This blog here shows you how to keep your SSH session alive.

On you client server (the one you connect from), open a terminal, type:

# vi /etc/ssh/ssh_config  -- Not sshd_config

add the following line to the end of the file:

ServerAliveInterval 60

Then save it.

Adding this line will allow your SSH session send a null packet to the remote server at every 60 seconds (for inactivity) to keep SSH connection alive. You can change the value if you feel is too short or too long.

Not root?

If you don't have root permission, you can create a "config" file in your home dir:
# touch ~/.ssh/config

Add the following two lines:

Host *
  ServerAliveInterval 60

Save and exit. Then do a

# service ssh restart

You are good to go.

No comments: