I have a Ubuntu Server 18.04.6 LTS on an Intel Core Quad Q6600 and old Gigabyte 965P-S3 motherboard. Right now SSH is unstable. Client loses connection after 10 minutes of inactivity, but there is no any error. Client just gets stuck. Server continues to keep connection and doesn't kill connection even after one hour. Is the problem possibly hardware?
1 Answer
OpenSSH generally does not close idle (or "lost") connections because there are many ways to define idleness, some which may differ from your definition. However, you can edit your SSH configuration file to include these two lines:
ClientAliveInterval 300
ClientAliveCountMax 2
This will disconnect connections that have not issued a command in 600 seconds (10 minutes).
From the Ubuntu Manpage for sshd_config
:
ClientAliveCountMax
Sets the number of client alive messages which may be sent without sshd(8) receiving
any messages back from the client. If this threshold is reached while client alive
messages are being sent, sshd will disconnect the client, terminating the session.
It is important to note that the use of client alive messages is very different from
TCPKeepAlive. The client alive messages are sent through the encrypted channel and
therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive
is spoofable. The client alive mechanism is valuable when the client or server
depend on knowing when a connection has become unresponsive.
The default value is 3. If ClientAliveInterval is set to 15, and
ClientAliveCountMax is left at the default, unresponsive SSH clients will be
disconnected after approximately 45 seconds. Setting a zero ClientAliveCountMax
disables connection termination.
ClientAliveInterval
Sets a timeout interval in seconds after which if no data has been received from the
client, sshd(8) will send a message through the encrypted channel to request a
response from the client. The default is 0, indicating that these messages will not
be sent to the client.
In plain language, the server will send a message every 300
(or however many) seconds to the client. If the client does not respond after 2
(or however many) attempts, the connection is closed.
Be sure to restart OpenSSH after modifying the configuration file, as it is only read at the time the daemon starts.
/var/log
to see if there are any errors or messages about broken pipes, connection drops, or anything else? If the issue is hardware related,syslog
may contain specific information pointing to a problem 🤔syslog
.auth.log
also doesn't contain any information about my issue. Server even doesn't know that client lost connection and keeps sshd process for this client until I kill this process