increase ssh timeout in linux

How to Disable Auto Logout in Linux

By default, Linux systems will automatically log out users after a specific amount of time. This means your SSH session will automatically end after the logout time, and all your processes that are running in foreground will terminate. This can be pretty annoying if you need to use terminal for a long time, or you have long running processes on your system, that you don’t want to stop. In this article, we will learn how to disable auto logout in Linux.

How to Disable Auto Logout in Linux

The default timeout settings are defined in SSH configuration file and need to be modified in order to increase automatic logout duration, or disable it.

1. Edit SSH configuration file

Open terminal and run the following command to open SSH configuration file in text editor.

$ vi /etc/ssh_config

Here are the 3 parameters that control SSH timeout.


Let us look at each of them individually.

  • ClientAliveInterval – Timeout interval in seconds after which is no data is received from the client, ssh server will send a message requesting a response from client, to keep the connection alive.
  • ClientAliveCountMax – Defines the maximum number of times SSH server will ask the client for a response, in case it does not receive any data. If SSH server does not get a response even after requesting a response for this many number of times, then it will disconnect the client.
  • TCPKeepAlive – Flag which specifies whether to keep the connection alive or not. If you set it to No, then SSH server will not sent any messages to client, to check if the connection has to be kept alive.

Here is a sample configuration to increase SSH timeout to 2 hours.

TCPKeepAlive yes
ClientAliveInterval 7200
ClientAliveCountMax 3

TCPKeepAlive flag is set to yes, to keep the connection alive. ClientAliveInterval is set to 7200 seconds, that is, 2 hours. So if your SSH server does not receive any data from client even after 2 hours, it will send a request to the client for response We have set ClientAliveCountMax to 3 so the SSH server will do this 3 times, once every 2 hours. So the total timeout duration is 3 x 2 hours = 6 hours.

Save and close the SSH configuration file.

If you don’t want server to send KeepAlive messages to the client, you can set TCPKeepAlive to No, thereby disabling it. In this case, the SSH server will simply disconnect after 2 hours of inactivity.

TCPKeepAlive no 
ClientAliveInterval 30
ClientAliveCountMax 240

Nevertheless, the SSH server will continue to send Alive message to client, every 30 seconds, to indicate that it is still up & running.

2. Restart SSH Server

Restart SSH Server to apply changes.

$ sudo systemctl restart ssh.service

Now SSH server will not logout as soon as it used to before.

Also read:

How to Make File Unreadable in Linux
How to Measure Elapsed Time in Python
How to Create ISO Image from CD in Linux
How to Export Pandas Dataframe to Multiple Excel Sheets
How to Export Pandas Dataframe to Excel

Leave a Reply

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