Disabling SSH Timeout When Connecting to/from Ubuntu

Last updated:
Disabling SSH Timeout When Connecting to/from Ubuntu
Table of Contents

SSH Timeouts

When using default configuration on Ubuntu, you might experience SSH Timeouts (i.e. the console you are using to connect to a remote server will seem to freeze) after a few minutes of lack of activity.

This is annoying because you need to open a new console instance and reconnect and perform any other steps you need before connecting.

Since using SSH to connect to remote servers is very common and linux being as old as it is, you would think that someone somewhere would have provided a solution for this problem by now; you'd be right.

SSH Client Configuration

In the server/computer you are connecting from

Open file /etc/ssh/ssh_config and set directive ServerAliveInterval to a value like 100:

# other configs
ServerAliveInterval 100

This causes your SSH client to send keep-alive messages every 100 seconds so that the server doesn't drop your connection.

Server Configuration

In the server you are connecting to

You must also configure the SSH remote Server you are connecting to (or ask whoever is responsible for doing it).

Open file /etc/ssh/sshd_config and add these configurations at the end of the file to ensure they're not overriden by later lines:

# other configs
ClientAliveInterval 600
TCPKeepAlive yes
ClientAliveCountMax 10

These are conservative settings that will make your SSH Server only disconnect after (600 * 10 = 6000) seconds of user inactivity. Customize these if you need more.

Restart the ssh server so that changes take effect:

$ sudo /etc/init.d/ssh restart


Dialogue & Discussion