Linux – Stop SSH From Timing Out

When managing a Linux server using SSH, default sshd settings automatically kill connections that stay open for too long without any activity. SSH connection timeouts are a great security measure but as this can be frustrating for system admins, here’s how to change this on the server side.

To change this behavior, it is possible to make the server send null packets to the client in order to prevent a timeout. These keep alive packets could be sent from clients as well, but I’m gonna focus on making changes to sshd, which is server side.

Open up this file:


and change these values:

ClientAliveInterval 60
ClientAliveCountMax 480

This will send a null packet every 60 seconds and will keep the connection alive for 8 hours (as 480 x 60 = 28.800s).

Finally restart sshd and you’re good to go.

 service sshd restart

Extra: if your terminal would be stuck anyway after a timed out ssh session, do this to unfreeze the terminal:

Press Enter, ~, . one after the other