Add in your ~/.ssh/config :

Host *
 ServerAliveInterval 240

src = superuser.com