Its session will be terminated when the SSH connection is not being used, which will disconnect the client machine. To avoid this, we can increase the session duration so that the session will not be disconnected for a long time due to the inactivity of the SSH.
The session’s timeout due to inactivity is beneficial for security purposes. However, it may be irritating sometimes.
This post will enlist the method to increase the SSH connection timeout. The content of the post is as follows:
- Prerequisites: Install and Enable SSH on the computer
- Set the Keep-Alive Option in the Server Configuration File
- Set the Keep-Alive Option in the Client Configuration File
Before proceeding with the method, we must fulfill the blog’s prerequisite.
Prerequisites: Install and Enable SSH on the computer
To learn the method of increasing the SSH connection’s timeout duration, ensure it is installed on both the client and the Host computer. If it is not, users can take help from the mentioned link to install and enable SSH on the computer.
After ensuring the installation of the SSH on the computer, we will increase the SSH connection Timeout duration.
Method 1: Set the Keep-Alive Option in the Server Configuration File
The first method to increase the SSH connection timeout is by making changes to the server machine’s SSH configuration file. When SSH is installed on the computer, its configuration file is copied to the server computer.
To make these changes, open the configuration file by using the nano text editor:
$ sudo nano /etc/ssh/sshd_config
The opened file will look:
In the configuration file, find out the ClientAliveInterval and the ClientAliveCountMax whose applications are explained:
|This value defines the timeout interval in seconds if no value is assigned then by default it is set to the 0 seconds.
|This is the counter to the alive messages sent to the client machine. If the maximum number of the alive messages get no response, then the SSH session will be the timeout
The timeout value is dependent on the above two mentioned values and can be calculated by using the formula:
Timeout value = ClientAliveInterval * ClientAliveCountMax
For example, if we assign “ClientAliveInterval” value of 3600 seconds and the counter of the “ClientAliveCounter” to the 3, then the timeout value will be set to 180 minutes. Assign these values in the configuration file:
Close the SSH configuration file after saving the changes made. Then restart the SSH using the command:
$ sudo systemctl restart sshd
The timeout of the SSH connection has been increased to 180 minutes.
Method 2: Set the Keep-Alive Option in the Client Configuration File
In this method, repeat all the steps explained to the server in the client machine. The only difference is ClientAliveInterval, and the ClientAliveInterval will replace the ServerAliveCountMax, and the ServerAliveCountMax, respectively. Users are supposed to add these two variables with the values in the file.
This method is recommended because if changes are made in the server machine, then it will apply to all the connected client machines. If the changes are made in the configuration file of SSH of the client machine, then it will apply only to that particular machine. This is much beneficial concerning security concerns.
These two methods can be used to increase the SSH connection Timeout.
To increase the SSH connection timeout, change the values of ClientAliveInterval, and the ClientAliveInterval in the Server’s SSH configuration file. Also, the session of timeout can be increased by adding the values of ServerAliveInterval, and the ServrAliveInterval in the client’s SSH configuration file. This blog explains both methods in detail to increase the duration of the timeout session, which is beneficial for Linux users.