Prevent SSH connection from timing out in Terminal

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:

1
$ vi ~/.ssh/config
$ vi ~/.ssh/config

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

1
ServerAliveInterval 60
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:

1
$ chmod 600 ~/.ssh/config
$ chmod 600 ~/.ssh/config

From here on out, no more timeouts.

Leave a Reply

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