I’v had to solve this problem a few times and thought that I would post it up here. The problem is basically that when ssh’ing into a machine in a remote location, sometimes your session will log off because a firewall or something in between is ending the connection.
The simple solution is to find the keepalive packet option and enable it on your ssh client.
On Windows using Putty:
I found the following configurations in the “Connection” section:
Seconds between keepalives (0 to turn off)
Enable TCP keepalives
Try setting it to 180 seconds and enabling the TCP keepalives.
Edit the /etc/ssh/ssh_config:
linux probably works the same as the OSX, but I’ve never actually ran into the problem on any of my connections.