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

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.

3 Answers

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

TCPKeepAlive yes
ServerAliveInterval 30
5

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 

Source

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)

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like