Prevent SSH connection from timing out in Terminal

Empty terminal with planes parked outside the windows.
Viktor Navorski was here.

If you’re constantly connected to multiple servers via SSH and perform work on them throughout the day, dealing with timeouts can be cumbersome. Here’s how you can keep the connection alive.

Create a config file in your home’s .ssh directory:

$ vi ~/.ssh/config

Add the following by pressing the letter i, typing in the text below, and pressing ESC followed by :wq:

ServerAliveInterval 60

Every 60 seconds a packet will be sent to keep the connection alive.

Lastly, modify the config file so that it’s read-only to you:

$ chmod 600 ~/.ssh/config

From here on out, no more timeouts.

Featured image by Samuel Sosina.