I admit it, I’m always with a lot of applications opened, Chrome with at least 6 tabs, Skype, Slack, PHPStorm or SublimeText, Airmail or Outlook for Mac, Photoshop and terminal.
I regularly login via SSH to VPS in Digital Ocean and AWS EC2 and then run some commands like:
wp plugin install wordfence
Then I go to the wordpress site and start adjusting the settings, but by the time I get back to the terminal (5 – 10 minutes), the SSH session is frozen, so I’m forced to open a new one. I honestly became tired of this, and I remembered that SSH was built on TCP and as such it should have some “Keep Alive” settings like on SIP (sorry I come from the call center world). And after some search online, I found that you can make this change both from the server side (SSHD: Secure SHell Daemon) or from your CLI (*nix, Linux & Mac).
Reduce SSH Timeouts from the server
Reduce SSH Timeouts from your computer
All you need to do is to setup your ssh client to send a “Keep Alive” signal to the server every certain amount of seconds. So you can add the following text to your ~/.ssh/config
file:
Host remote-host HostName remote-host.com ServerAliveInterval 120
This basically tells your computer to send “keep alive” signals to remote-host.com every 120 seconds (2 minutes). That way the session will not get frozen for that server.
If you want to enable this for all of the hosts that you connect to, then simply add the following strings instead:
Host * ServerAliveInterval 120
This will setup the “keep alive” signal interval to 2 minutes for any host that you connect to via SSH.
After you finish editing the file, please make sure to change the permissions on the file using the following command:
chmod 600 ~/.ssh/config
And there you go, as simple as that! No more timeouts on my terminal app on my Mac OS El capitan MBP!
Ha! Visited this 2 years later and it works like a charm!