ssh to Ubuntu Server hangs after 30 seconds of inactivity

Lets say I ssh to my 13.04 server from my Linux box and then vim file and do some text editing. If I pause for 30-60 seconds, considering what to type, then the terminal will hang. The cursor box continues to blink, but nothing in the terminal changes. It takes no keyboard input. It never disconnects, never gives me another message, display any errors. I have to close the console window to get out of it.

What is this, how can I get out of it when it happens, and how can I prevent it from happening in the future?

The result of grep -Hi Alive /etc/ssh/ssh*_config on the server:

/etc/ssh/ssh_config:ServerAliveInterval 30 
/etc/ssh/sshd_config:TCPKeepAlive yes

There are no results for grep -i alive /etc/ssh/ssh_config


Solution 1:

I think the issue is that you've not set ServerAliveInterval on the client. As explained in man ssh_config:

ServerAliveInterval

Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server, or 300 if the BatchMode option is set. This option applies to protocol version 2 only. ProtocolKeepAlives and SetupTimeOut are Debian-specific compatibility aliases for this option.

So, if I'm right, simply adding this line to your /etc/ssh/ssh_config file on the client should fix the issue:

ServerAliveInterval 30

That will send the keep alive messages every 30 seconds. That's kind of frequent but once you make sure that fixes it, you can reduce the frequency as needed.