How to Change SSH Connection Timeout in Linux
The ssh connection timeout due to inactivity is annoying and won’t let you focus on doing your tasks. But you can easily change the SSH connection timeout limit and keep the SSH session alive even after some inactivity. It will happen by sending a “null packet” between the client and the server at a specified interval that is smaller than the timeout value, we can avoid SSH timeout and keep the session alive.
Related article: Enable SSH on RHEL/CentOS 8.x.
Change SSH Connection timeout
As a Linux admin, you can add the following to your SSH daemon config in /etc/ssh/sshd_config
on your servers to prevent the clients from time out – so they don’t have to modify their local SSH config.
nano /etc/ssh/sshd_config
Try to scroll down and locate the following parameters:
ClientAliveInterval ClientAliveCountMax
The ClientAliveInterval
parameter specifies the time in seconds that the server will wait before sending a null packet to the client system to keep the connection alive. And theClientAliveCountMax
parameter defines the number of client alive messages which are sent without getting any messages from the client.
ClientAliveInterval 120 ClientAliveCountMax 720
This will make the server send the clients a “null packet” every 120 seconds and not disconnect them until the client has been inactive for 720 intervals (120 seconds * 720 = 86400 seconds = 24 hours).
You can achieve the same result by specifying the ClientAliveInterval
parameter alone to ClientAliveInterval 3600
To get the changes effected, reload the SSH daemon with systemctl reload sshd
command.
$ sudo systemctl reload sshd
Read about configuring SSH on Cisco Router/Switch.