How do I resolve a ssh connection closed by remote host due to inactivity?

11

8

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

superuser@thecolo:~$ Connection to 10.123.45.67 closed by remote host.
Connection to 10.123.45.67 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.

Thierry Lam

Posted 2012-12-20T15:45:53.710

Reputation: 3 497

Answers

16

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

TCPKeepAlive yes
ServerAliveInterval 30

balkian

Posted 2012-12-20T15:45:53.710

Reputation: 684

8

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 user@some.host.com

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 user@some.host.com

Source

ricciocri

Posted 2012-12-20T15:45:53.710

Reputation: 206

0

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)

Andrew

Posted 2012-12-20T15:45:53.710

Reputation: 881

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 – 2012-12-20T15:51:53.810

Keepalive will be on the client... in your case, your Mac. There will be an option somewhere! – Andrew – 2012-12-20T15:57:07.857