In this blog we are going to see how to increase session timeout in openssh server.
The can be done in two ways, you can either set this on server side or you can set this on client side. Let’s check both ways.
ServerAliveInterval: Number of seconds that the client will wait before sending a null packet to the server (to keep the connection alive).
ClientAliveInterval: Number of seconds that the server will wait before sending a null packet to the client (to keep the connection alive).
On Server Side
On the Server side, update client timeout. Increase Client interval in sshd_config,
Update following parameters & restart the sshd server, (set for 3600 x 2 = 2 hours)
ClientAliveInterval 3600 ClientAliveCountMax 2
Restart sshd server,
systemctl restart sshd
On the Client side
If you are using openssh as client, then on the client side, increase serveralive interval in the config below,
vi /etc/ssh/ssh_config or vi /root/.ssh/config
Add the below lines under the config & save
HOST * ServerAliveInterval 60 ServerAliveCountMax 2
Above configuration will poke server every 60 seconds if its alive or not. Will retry 2 times.
If you are using Putty as your client, then, we need to set a time interval (60 seconds in below example) in order to keep the session alive. This will keep the session alive by poking it every 60 seconds.