If you are new to using VPS services or Linux-based servers and still rely on tutorials for management, you really should increase your SSH timeout.
As I have experienced before and perhaps still do, when opening SSH while following a tutorial, sometimes we spend too long reading and when we return to SSH, the connection has already dropped because it was inactive for a few minutes, which means we have to log in again, which can be annoying.
Fortunately, we can increase the SSH timeout so you can stay connected to SSH even if you do not do anything for a few minutes, or even a few hours, by sending an empty message or null to the system.
How to Increase Linux SSH Timeout
To increase this Linux SSH timeout, we will perform several steps, including
- Login to SSH
- Edit the SSH Daemon Configuration File
- Adjust Client Alive
- Reload the SSH Daemon
1. Login to SSH
The first thing you need to do is log in to your SSH server, either using PuTTY or directly using CMD or Terminal.
If you are using CMD or Terminal, you can use the command below
ssh username@IP_Server -p 22For example, if you are going to log in to server 192.168.1.1 as the root user and the SSH port used is 1746, then the command used will look like this
ssh [email protected] -p 1746If you are using the PuTTY application to log in to the same IP address, username, and port, the configuration will look like this, then click the Open
2. Edit the SSH Daemon Configuration File
Now that you have successfully logged in to SSH, you can proceed to the next step to increase the SSH timeout by editing the SSH Daemon configuration file.
Depending on the file editor you use, you may need to use a different command .
If you are using the VI editor, you can use this command instead
sudo vi /etc/ssh/sshd_configBut if you are using the nano editor, you can use this command instead
sudo nano /etc/ssh/sshd_config3. Adjust Client Alive
After being inside the file editor to edit the /etc/ssh/sshd_configfile, you can then look for the following two lines to adjust the SSH timeout
#ClientAliveInterval #ClientAliveCountMaxClientAliveInterval is used here to determine the time in seconds that the server will wait before sending an empty packet to the client (the device you are using) so that it can stay connected.
On the other hand, ClientAliveCountMax is used to determine the number of ClientAlive messages sent to the client without receiving any message or action from the client. If the specified number reaches the limit and still does not receive a reply or action from the client, then SSHD will terminate the connection and you will be logged out of the SSH session.
To calculate the SSH timeout, you can use the following formula
Waktu Timeout = ClientAliveInterval * ClientAliveCountMaxSo, for example, if you want to set a 15-minute timeout and automatically log out when there is no activity, you can use the configuration ClientAliveInterval 300 * ClientAliveCountMax 3 = 900 seconds (15 Minutes), or it will look like this in SSH
ClientAliveInterval 300ClientAliveCountMax 3When using both parameters above in the /etc/ssh/sshd_config file, your SSH connection will automatically disconnect 15 minutes after you stop doing anything.
However, if using the calculation above is too confusing, you can just use the ClientAliveInterval parameter and ClientAliveCountMax does not need to be activated (without removing the comment from the line of code). For example
ClientAliveInterval 300Once you have determined it, you can save the changes to the SSH daemon configuration file and proceed to the next step.
4. Reload the SSH Daemon
So that the changes to the Daemon configuration you saved can take effect, you need to restart the SSH Daemon using the command below
sudo systemctl reload sshdAfter the SSH Daemon has been successfully reloaded, the new timeout should be working. However, if it still does not work, you can try logging in to SSH again or even rebooting your server.
COMMENTS
Loading...