Skip to content

Instantly share code, notes, and snippets.

@pierdom
Last active September 7, 2017 07:58
Show Gist options
  • Save pierdom/05e8c2e14dba5907a055208c5230a4be to your computer and use it in GitHub Desktop.
Save pierdom/05e8c2e14dba5907a055208c5230a4be to your computer and use it in GitHub Desktop.
[Three methods for avoiding timeouts during SSH sessions] #linux #macosx #sysadmin #networking

How to disable SSH timeout

Three methods for avoiding timeouts during SSH sessions.

Client-side methods

Use Client-side methods if you have no admin rights on the SSH servers or do not what to alter server's settings. This methods consists in instructing the client to send a keep alive every specified interval.

If you have admin rights on the client

On Debian/Ubuntu, edit file /etc/ssh/ssh_config and add the following line:

ServerAliveInterval 100

where 100 is the interval for sending the keep alive method in seconds. With this client-side method, the client will send a keep alive by default to every SSH server it will connect.

If you don't have admin rights on the client

On every Unix system, edit file ~/.ssh/config (create it if it does not exist yet) and add a configuration block for the specific server:

Host myserverconfig
	Hostname serveraddr
	User username
	Port 22
	Compression yes
	ServerAliveInterval 100

This settings will be valid only for the current user and only for the specific server. Of course, the settings such as Hostname, User, etc., should be properly edited.

Server-side method

Use this method if you have administrative rights on the server. These settings will be valid for each user will connect to the server.

On Debian/Ubuntu, edit the file /etc/ssh/sshd_config, changing the entries ClientAliveInterval, TCPKeepAlive and ClientAliveCountMax as in the example below:

ClientAliveInterval 100 
TCPKeepAlive yes 
ClientAliveCountMax 99999

To apply the new settings, restart the SSH server:

sudo /etc/init.d/sshd restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment