The TMOUT environment variable provides a partial solution, but still has holes. That will get rid of annoying short timeouts due to the network or similar idle timeouts outside of sshd and your shell, but it does create the new problem of user sessions that may never timeout when idle.
If this sounds similar to your problem, then you probably want to set ClientAliveInterval to a relatively short time, like 60 seconds, rather than 1200 or 5000 like the earlier commenters. In actuality, they’ll happily stay open for days if I don’t manually end them. With my current ClientAlive settings, my sessions would die after 90 seconds of inactivity if this article was correct. Setting ClientAliveInterval to a shorter value than the firewall’s timeout value solved that problem by forcing ClientAlive messages to be sent over the connection periodically if there was no other traffic and thereby keeping the connection alive on the firewall. I’d then need to wait about 5 minutes for the client to finally time out and realize that the TCP connection was dead and exit.
#Your pandora session timed out problem windows#
When working on 3 screens with 2 or 3 shell sessions open, I would often encounter the problem when working predominantly in one window, the other windows would freeze after about 30 minutes. This was the initial problem I set out to solve. The one thing that you can use ClientAliveInterval to solve is if you have a firewall timing out your NAT session after an annoyingly short idle time. If you happen to walk away whilst editing a file in vi or something like that, you again have an effectively infinite idle timeout. So far, the best solution I can find for that is to set the TMOUT environment variable in bash, although this only works at the primary shell prompt. That’s the problem I’m really trying to solve. What it won’t do is kill off the session if the user walks away from their terminal for more than 5 minutes. So if you set the interval to 60 and the MaxCount to 5, then you have some clients unexpectedly die due to a power failure or become inaccessible due to a network outage, the session will be killed off on the server about 5 minutes later. This allows the client to respond over the channel that it is still alive and allows the server to clean up sessions where either the network connection has been interrupted or the client has died without gracefully disconnecting. If you set ClientAliveInterval to a non-zero value, the server will send ClientAlive messages over the encrypted channel if it doesn’t see traffic from the client for that many seconds. Unfortunately, this is not what ClientAliveInterval and ClientAliveMaxCount do. I am looking for a way to get the ssh daemon to enforce an idle timeout for users, which it seems many others are also looking for. This “solution” to set an idle timeout seems quite common on the internet, but it’s not actually correct. This is to prevent someone from walking by and hijacking your session when you are away for an extended period of time. $ sudo systemctl reload sshdĪs an SSH security measure, it’s always advisable not to set the SSH timeout value to a huge value. Once done, reload the OpenSSH daemon for the changes to come into effect. This is an equivalent of 1 hour, which implies that your ssh session will remain alive for idle time of 1 hour without dropping.Īlternatively, you can achieve the same result by specifying the ClientAliveInterval parameter alone. The Timeout value will be 1200 seconds * 3 = 3600 seconds. Timeout value = ClientAliveInterval * ClientAliveCountMaxįor example, let’s say you have defined your parameters as shown:
The timeout value is given by the product of the above parameters i.e. If this limit is reached while the messages are being sent, the sshd daemon will drop the session, effectively terminating the ssh session.
On the other hand, the ClientAliveCountMax parameter defines the number of client alive messages which are sent without getting any messages from the client. The ClientAliveInterval parameter specifies the time in seconds that the server will wait before sending a null packet to the client system to keep the connection alive. Scroll and locate the following parameters: