linux – Dropping SSH connection after 5 minutes of inactivity


The connection keeps dropping after 5 minutes of inactivity:

  • I connect to my server via SSH
  • I go to Google to look for a command, for example, to find a file
  • go back and the git bash window is not responding
  • restarting it
  • re-enter password …

This is extremely annoying! Why and what to do about it?


Usually the sshd server will close inactive connections. I often came across that routers also terminate connections that are "silent" for some time.

You can persuade the client to send an I-live signal all the time. In ~/.ssh/config add (in seconds):

Host * 
ServerAliveInterval 120 

If the file still does not exist, you need to create and in order to avoid an error

Bad owner or permissions on ~ / .ssh / config

remember to change the write permissions (in some versions also read):

chmod go-rw ~/.ssh/config
# или
chmod 600 ~/.ssh/config

Without configuration, you can try: ssh -o ServerAliveInterval=120

More man 5 ssh_config

In PuTTY, this is set in the menu – Connection> Seconds between keepalives (0 to turn off).

Scroll to Top