What exactly causes a ssh connection to interrupt? When you idle for a while, it disconnects.
How do I keep the connection alive (without autossh
or reconnect)?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThis is most likely a firewall which cuts your idle connection after a while.
You can configure the openssh
server or client to send a KeepAlive after a while.
Send a KeepAlive every 5 minutes to the server:
ssh user@server -o ServerAliveInterval=300
If you have control over the openssh-server
, you can also send KeepAlives to the client after a defined interval. Add the following to /etc/ssh/sshd_config
:
ClientAliveInterval 300
TCPKeepAlive yes
TCPKeepAlive
should be yes
by default.
Restart the openssh-server
after the modification:
/etc/init.d/ssh restart
Here are a few things you can try:
1) It's most likely the shell which is timing out. Disable the timeout by unsetting TMOUT
in your profile. TMOUT
is the number of seconds that bash waits for input before terminating. Echo $TMOUT
to see if it is set. Add the following to your profile:
unset TMOUT
2) Configure PuTTY to send keepalive packets by going into:
Settings > Connection > Seconds between keepalives = 60
3) Tweak your sshd_config
(normally found in /etc/ssh
) and add:
TCPKeepAlive yes
ClientAliveInterval 60
Save the file and restart sshd
.
ClientAliveInterval
ClientAliveCountMax 1440
will allow the connection to time out after 1440 minute checks (1 day). You can adjust this to extend the timeout but not disable it completely.
Nov 21, 2019 at 17:09