Keep your SSH session from timing out

Posted on November 14, 2011

So there you are, working away on your web server making something magical through ssh. You get a phone call, or check Twitter, read an article or something. It was only a few minutes!
You go back to your terminal, and it just doesn’t respond, for the 50th time today. Now you get to start all over again reconnecting any sessions you may need for what you are doing.

What is happening is that the server has not received any data, and your session timed out.

There is an easy command that takes care of this when you connect:

ssh -o ServerAliveInterval=60 username@domain.com

This will send the server a bit every 60 seconds if you don’t, keeping your connection alive indefinitely.