How to disable SSH timeout

From Brian Nelson Ramblings
Jump to: navigation, search

How to disable SSH timeout

SSH clients will automatically be disconnected from the server and prompt the below message after being idle or inactive for a while.

Read from remote host Connection reset by peer
Connection to closed.

This is due to the SSH servers' configuration (often by default) to avoid hanging sessions and free up resources.

Disable SSH Timeout Server Side

If you have administrative access to the SSH servers, you can configure it so that it will not easily disconnect idle sessions. This could be achieved by setting the parameters for TCPKeepAlive, ClientAliveInterval, and ClientAliveCountMax as per the following;

TCPKeepAlive no  
ClientAliveInterval  30
ClientAliveCountMax 240

SSH server configuration file is normally /etc/ssh/sshd_config. Restart the SSHd service for the changes to take effect.

Disable SSH Timeout Client Side

If you don't have administrative access to the server, you can configure your SSH client to send the alive message to the server instead to achieve the same result. The key here is the ServerAliveInterval option for the SSH client.

You can do this by updating /etc/ssh/ssh_config (applying the setting to every user in the system) or in ~/.ssh/config (single user).

Set the following option to have the client send the alive packet every 30 seconds to the server.

ServerAliveInterval 30

Disable SSH Timeout Per Connection

The other alternative is to manually set the ServerAliveInterval option every time you're connecting to a server by using the -o ServerAliveInterval=<time-in-second> prefix as the following example;

ssh -o ServerAliveInterval=30