If you are following a security technical implementation guideline it currently states
ClientAliveInterval 600
ClientAliveCountMax 0
that will disconnect and idle ssh session (i.e. a putty window) after 10 minutes.
In RHEL 7 the default values for those two items, from a clean install from rhel-server-7.9-x86_64-dvd.iso, or centos, is 0
and 3
respectively which results in an ssh session never auto terminating.
see for more detail: https://stackoverflow.com/questions/71174746/clientaliveinterval-is-not-closing-the-idle-connection
most relevant: These are not for user-idle circumstances, they are - as that man page excerpt notes - for unresponsive SSH clients. The client will be unresponsive if the client program has frozen or the connection has been broken. The client should not be unresponsive simply because the human user has stepped away from the keyboard: the ssh client will still receive packets sent from the server.
It is at the client, in putty.exe, under Connection and Options for controlling the connection there is seconds between keepalives (0 to turn off). That by default is 0. Set that to a number less than the ClientAliveInterval
set in sshd_config
.
If not using putty.exe, from Windows, and using ssh from another linux box, then the client ssh is config'd via /etc/ssh/ssh_config
however there is no corresponding item in there that I am aware of to send a keepalive packet every so often.
Note: using putty.exe from windows with its default keepalive of 0, and the ssh server having a ClientAliveInterval set, even having vi
open will get disconnected resulting in a lost file that vi
will recover via its .swp file. Or if running a program constantly spitting output, that is from the server side and the ssh connection will get terminated killing your job... there has to be something from the client side (a key press) that counts and causes a keepalive. So with putty.exe from Windows it's a fairly easy fix, for ssh from linux to linux I don't know how to prevent disconnect without a keyboard key press at the client side in the ssh session.
update: from linux to linux it seems you need to use ssh -o
and various options. See for more details: How does tcp-keepalive work in ssh?
for example:
ssh -o ServerAliveInterval=5 -o ServerAliveCountMax=1
kinda like with /etc/yum.conf having gpgcheck=1, and just doing yum install --nogpgcheck :)
ssh -o ConnectTimeout=3 -f -L 3306:localhost:3306 "$user@$ip" sleep 10800
. This may work for you by holding an active session open for the specified time.screen
ortmux
to be able to reconnect to the session without losing data.