It’s actually fairly simple. In your SSH config file, you add this:
Host *
ServerAliveInterval 240
The *
after the host can be whatever host you want it to apply to, and *
simply means to apply this to all hosts. So you could also apply it this way:
Host example.com
ServerAliveInterval 240
Also, if you aren’t sure where your SSH config file is, on a UNIX based system, it’s generally in ~/.ssh/config
.