Keeping ssh connections alive

Picture this; you come back from lunch at "My Old Dutch Pancake house" and every one of your ssh connections has been closed due to lack of activity. It's reasonable that the server you are connected to (or the hardware you are connecting through) closes connections due to idling, but it's such a pain to have remember each and every directory you were working on to be able to pick up where you left off. To remedy this there is a very simple thing you can do which will prevent your ssh connections from terminating prematurely.

On the mac (linux distributions should be similar) open terminal and type (you should be in your home directory if not type 'cd ~' first):

ls -al

You should see a list of files including the directory .ssh (the -a switch shows all files including hidden ones) Hidden files are not shown by default on the mac and if you would always like to see hidden files in bash you can add an alias for ls -a to your .bash_profile. I'll cover this in a future post.

Next change directory into the .ssh directory (if it doesn't create it first with 'mkdir .ssh'):

cd .ssh

Now open the file called 'config' and add the following line (again you will need to create it if it doesn't exist already):

ServerAliveInterval 240

This will now send a packet of data every 4 minutes so that your ssh session does not get disconnected. Job's a good 'un!