The Ubuntu Blog has a nice lil' article
about keeping SSH sessions alive
It basically boils down to editing your /etc/ssh/ssh_config
file and
adding the following:
# /etc/ssh/ssh_config
ServerAliveInterval 5
The number is the number of seconds to send the small keep alive which keeps the connection open. Ubuntu Blog suggests changing it from 5 to 240 or 300 (4 or 5 minutes).
– Chris