SSH timeout prevention – keep SSH sessions alive

SSH timeout due to inactivity is annoying. Here’s how to keep your SSH sessions alive and prevent the SSH timeout:


By sending a “null packet” between the client and the server at a specified interval that is smaller than the timeout value, we can avoid SSH timeout. It doesn’t matter if the packet is sent from the client or the server, as long as there is some communication going on between the two.

If you setup your SSH client to send the “null packets”, you’ll prevent an SSH timeout on all the SSH connections you make from your computer. If you are annoyed with your own SSH sessions timing out when you’re connected to servers, this is what you want to do.

If your clients (customers, users, kids) are fed up with the SSH timeout, you can either instruct them on how to configure their SSH clients – like pointing them to this article – or you can configure the server itself to avoid SSH session timeout. To do that, you setup the SSH server to send the “null packets”, and you’ll prevent a timeout on all the SSH connections every client makes to the server.

Fortunately, the setups are not exclusive, so you may setup both your client and all your servers and everything will run smoothly.

Prevent SSH timeout on the client side

If you’re on Mac or Linux, you can edit your local SSH config file in ~/.ssh/config and add the following line:

This will send a “null packet” every 120 seconds on your SSH connections to keep them alive.

Prevent SSH timeout on the server side

If you’re a server admin, you can add the following to your SSH daemon config in /etc/ssh/sshd_config on your servers to prevent the clients to time out – so they don’t have to modify their local SSH config:

This will make the server send the clients a “null packet” every 120 seconds and not disconnect them until the client have been inactive for 720 intervals (120 seconds * 720 = 86400 seconds = 24 hours).

There are 13 comments

I love comments that bring new insights, shares ideas and experiences, and most of all: corrects my mistakes. For support questions, there are other fora, like Stack Overflow, Server Fault and the WordPress support forum.

Your email address will not be published. Required fields are marked *