Technical article 128001

My ssh sessions are getting dropped after some idle time, can I improve this situation?

OpenServer Definitive 2018UnixWare 7 Definitive 2018OpenServer 6UnixWare 7

Written · Last revised

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 6

Change 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 6

If 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 6

This 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

From the Xinuos technical article database, record 128001. Reproduced with permission. The original is at www.sco.com/ta/128001, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.