Initiate the process by establishing an SSH connection to your VPS, then proceed to modify your OpenSSH configuration file
nano /etc/ssh/sshd_config
Scroll down in the file and find the settings: ClientAliveInterval and ClientAliveCountMax
The ClientAliveInterval (in seconds) is a timer that waits until it reaches zero (0). When it reaches zero it will send a null packet to the VPS that the connection may be terminated.
The ClientAliveCountMax counts how many times the ClientAliveInterval has been reached. When it reaches the value it currently has, the connection will be terminated.
By increasing the values of both, we are able to be longer inactive while the SSH connection stays alive. By default the ClientAliveInterval is at 0 and the ClientAliveCountMax at 3.
Let’s start by setting the following values:
ClientAliveInterval 300
ClientAliveCountMax 6
(Do not forget to remove the hashtags before the values (#))
Save & exit the sshd_config file.
The last step is to restart the OpenSSH service, do this by executing the following command:
service sshd restart
You have now increased the inactivity timers for SSH. Your connection should stay alive longer while idling.