SSH connection – after some time I can’t type anything

sshterminal

This keeps hapenning on which ever server I am connected to. I type:

ssh user@server

I log in, everything works for a couple of minutes. But after some time, possibly when I switch to other programmes (browser, ftp client etc) when I try to type anything back in the terminal, the cursor stops blinking while I type, but nothing actually gets typed. I can't execute any command, and all I can do is close the terminal window, reopen it and reconnect.

If it's of any importance, I'm running Ubuntu 12.04 on my local machine.

Best Answer

You have a NAT router or a similar stateful firewall between your client and the server. When you opened the TCP session, the firewall remembered that a TCP connection was created between your client port and the server port. As long as the firewall remembers the connection, it will continue passing packets between the client and the server.

The session "breaks" because the firewall forgets about the connection and stops passing packets through. The firewall may forget about the connection because it has a timeout on idle connections. Or it could forget because it has a limited amount of memory and too many new connections were being created for it to remember all of them.

ssh has some options to work around this by sending periodic "keep-alive" packets when the connection is idle. Look at the TCPKeepAlive, ServerAliveInterval, and ServerAliveCountMax options.