Problem
Most modern firewalls will drop idle connections after a period of time which can interfere with sshd's default TCPKeepAlive mechanism.
Solution
Replace sshd's TCPKeepAlive mechanism with the ClientAlive probing mechanism.
To do so, edit your /etc/ssh/sshd_config file and make
modifications. Find or add comments about the TCPKeepAlive
option and set it to 'no'. Some modern configuration files might
already have the ClientAlive* options commented out:## Firewall workaround
## turn TCPKeepAlive off and check the client every 5 minutes
TCPKeepAlive yes
## fail after 6 tries (30 minutes)
#ClientAliveInterval 300
#ClientAliveCountMax 6Change these settings, so that TCPKeepAlive is disabled (no) and the ClientAlive* options are set. Resulting in something like:
## Firewall workaround
## turn TCPKeepAlive off and check the client every 5 minutes
TCPKeepAlive no
## fail after 6 tries (30 minutes)
ClientAliveInterval 300
ClientAliveCountMax 6If you don't have these options in your sshd_config file, you can simply add them to the end of your /etc/ssh/sshd_config file.
Anytime /etc/ssh/sshd_config is updated, sshd will need to
be restarted. Find the parent /etc/sshd process and send
it a SIGHUP (-1), using this syntax:ps -ef|grep sshd|grep -v grep|grep -v -- " -R"|grep -v "sshd:"
kill -1 <PID_of_sshd>Alternatively, the changes will take effect during the next reboot.
NOTE: If you still experience idle time disconnects, you might try
reducing the ClientAliveInterval value to 2 minutes (120).NOTE: If you need to allow for more idle time than 30 minutes,
the ClientAliveCountMax should be increased instead of the
ClientAliveInterval. Increasing the ClientAliveInterval
too much will not prevent the firewall from dropping idle
connections.NOTE: The changes above will extend the idle timeout for all ssh logins.
If you would prefer to only extend the idle timeout for specific
clients, you can adjust values in the client's ssh_config file, or
~/.ssh/config and set similar ServerAlive* parameters, for example:ServerAliveInterval 60
ServerAliveCountMax 6This will enable server probing from the client and also keep the idle connection active even when the firewall blocks TCPKeepAlive probing.
NOTE: TCPKeepAlive mechanisms can be spoofed since they use the normal
TCP channel and therefor are not encrypted, however, ClientAlive*
& ServerAlive* mechanisms use the ssh channel and are encrypted
and will not be blocked by the firewall since it can not be
distinguished from normal ssh traffic.NOTE: telnetd still relies on the older TCPKeepAlive mechanism and does
not have a workaround to this situation. It is recommended that
telnet connections be replaced by more secure ssh connections if
possible. See also
http://osr507doc.xinuos.com/cgi-bin/man?mansearchword=sshd_config&mansection=5&lang=en
http://osr507doc.xinuos.com/cgi-bin/man?mansearchword=ssh_config&mansection=&lang=en