How to keep OS X Terminal client connections alive when idle

There are three ways to keep your SSH client connection alive, even when it is idle and you are away doing something else:

You can add the ServerAliveInterval command line option to each individual connection you setup, for example: ssh o ServerAliveInterval=30 hostnameofservertoconnectto.com

You can add the same option to your personal SSH config file in ~/.ssh/config like this:

ServerAliveInterval 30

Or just for specific servers:

Host server1.com server2.com
ServerAliveInterval 30

You can add the same option to the system SSH configuration file in /etc/ssh/ssh_config like this:

ServerAliveInterval 30

Or just for specific servers:

Host server1.com server2.com
ServerAliveInterval 30