You can configure the ssh client to automatically send a protocol no-op code code every so many seconds so that the server won’t disconnect you. This is setting is sometimes referred to as Keep-Alive.

Global Configuration

Add the following line to the /etc/ssh/ssh_config file:

ServerAliveInterval 60

The number is the amount of seconds before the server with send the no-op code.

Current User Configuration

Add the following lines to the ~/.ssh/config file (create if it doesn’t exist)

Host *
ServerAliveInterval 60

Make sure you indent the second line with a space.

Per-Host Configuration

If you only want to enable keep alive for a single server, you can add that into the ~/.ssh/config file with the following syntax:

Host *hostname.com
ServerAliveInterval 60

 

Note: Most Windows based SSH clients like Putty have a configuration option for enabling keepalives as well.  Every 60 seconds is a good recommended value.

Leave a Reply

Your email address will not be published. Required fields are marked *