Disabling SSH Timeout When Connecting to/from Ubuntu

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.


To increase the time a connection stays open you need to add configuration both to the client and the server

Client side

In the server/computer you are connecting from

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

# other configs above

ServerAliveInterval 60

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


In the server you are connecting to

You must also configure the SSH remote Server you are connecting to.

Open file /etc/ssh/sshd_config and add these configurations1 at the end of the file.

# other configs above

ClientAliveInterval 600
TCPKeepAlive yes
ClientAliveCountMax 10

Restart the ssh server so that changes take effect:

$ sudo /etc/init.d/ssh restart


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