Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently trying to ssh to a colo, after 1 to 2 minutes of inactivity, I get:

superuser@thecolo:~$ Connection to closed by remote host.
Connection to closed.
mylocalmac:~ superuser$

As long as I am typing something in the ssh terminal, the connection is kept. As soon as 1 to 2 min of inactivity has happened, I will get the above message. The machine I'm trying to connect to is a Ubuntu 12.04.1 LTS 64 bit server edition. It's not a physical server but a guest VMware. I'm sshing from a mac terminal.

Please don't confuse this question with similar ones on this site with the keyword ssh_exchange_identification in it, it's unrelated.

share|improve this question
up vote 3 down vote accepted

Add the following to your .ssh/config and all your ssh connections will send a KeepAlive every 30 seconds:

KeepAlive yes
ServerAliveInterval 30
share|improve this answer

If you are connecting from a Linux computer you can use some options directly from the command line

TCPKeepAlive: This uses the KEEPALIVE option of the TCP/IP protocol to keep a connection alive after a specified interval of inactivity. On most systems, this means 2 hours. So, with the TCPKeepAlive option passed to SSH, the SSH client will send an encrypted packet to the SSH server, keeping your TCP connection up and running.

ssh -o TCPKeepAlive=yes

ServerAliveInterval: This sets a timeout interval in seconds, which is specified by you, from which if no packets are sent from the SSH client to the SSH server, SSH will send an encrypted request to the server for a TCP response. To make that request every 30 seconds:

ssh -o ServerAliveInterval=30


share|improve this answer

You need to "keepalive"

Depending on your client, this maybe trivial or just easy - it shouldn't be any harder!

For example, in putty it's on the connection option (set keepalive to a non-zero value)

share|improve this answer
Where do I set the keepalive? On the server or from my mac? Where should I set that value and what's the recommended value? – Thierry Lam Dec 20 '12 at 15:51
Keepalive will be on the client... in your case, your Mac. There will be an option somewhere! – Andrew Dec 20 '12 at 15:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .