Since several days ago, whenever I connect to this server via ssh, it freezes very easily. To my impression, it seems that the idle timeout is set to a very short period. However, after checking the sshd_config file, it has not been changed for several months. Confused…

Today, I was working on upgrading the eZ publish in SCIM project from version 3.5.x to 3.8.x. It was really annoying that the ssh froze every now and then: I kept reconnecting/rediring to the working path/re-opening vim to edit the files.

Finally, I decided to face the issue and solve it!

Googling… first I came across the option ServerAliveInterval and ServerAliveCountMax, more details from the man page:

ServerAliveInterval

Sets a timeout interval in seconds after which if no data has been received from the server, ssh 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. This option applies to protocol version 2 only.

As the name suggested, option ServerAliveCountMax means after this times without responses from server, disconnect.

Thus I added these two lines in my ~/.ssh/config

ServerAliveInterval 30
ServerAliveCountMax 0

Try reconnecting to the server, and waited patiently for it to freeze… Ah, it did not freeze any more: after printing an error message ” Disconnecting: Timeout, server not responding.“, ssh exited.

Uhm, not so good, but at least exiting is better than freezing my terminal. Continue to googling…

It turns out that the disconnecting/freezing of my ssh suddenly several days ago is caused by some firewall settings: it setups a very very short time The firewall I am behind is the university one and I can not modify it, so I have to find out a workaround.

Fortunately sshd has two corresponding options for the server end as well, and this ClientAliveInterval option specifys how often to request a response from client. After setting it to 20 (seconds) in the sshd_config file and restart the sshd server, all the annoying behaviors are gone for good ;)