SSH connection goes down automatically after a specified period of time set by ClientAliveInterval
and ClientAliveCountMax
parameters and their client-side equivalents. If these timeouts are quite high you will experience a frozen shell. However, if you use OpenSSH
you don't have to wait for a timeout and can force closing a connection using escape characters:
ESCAPE CHARACTERS
When a pseudo-terminal has been requested, ssh supports a number
of functions through the use of an escape character. A single
tilde character can be sent as ~~ or by following the tilde by a
character other than those described below. The escape character
must always follow a newline to be interpreted as special. The
escape character can be changed in configuration files using the
EscapeChar configuration directive or on the command line by the
-e option.
The supported escapes (assuming the default ‘~’) are:
~.
Disconnect.
(...)
When connection freezes press ~ (that means Shift+` keys together), release it and press ..
Alternatively, if you work with an unstable connection or need to be connected to the remote server all the time you can use autossh to automatically renew lost connection, it's very convenient.
EDIT:
However, if both ClientAliveInterval
and ServerAliveInterval
are set to 0 explicitly or are not set explicitly and are then set to 0 by default according to sshd_config
and ssh_config
manpages, timeout settings are set in the following files (from http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/usingkeepalive.html):
# cat /proc/sys/net/ipv4/tcp_keepalive_time
7200
# cat /proc/sys/net/ipv4/tcp_keepalive_intvl
75
# cat /proc/sys/net/ipv4/tcp_keepalive_probes
9
The first two parameters are expressed in seconds, and the last is
the pure number. This means that the keepalive routines wait for
two hours (7200 secs) before sending the first keepalive probe,
and then resend it every 75 seconds. If no ACK response is
received for nine consecutive times, the connection is marked as
broken.
You can modify these 3 files just by using echo
and see yourself that a frozen SSH session is disconnected according to these values.