Tutorial: How to prevent freezing of SSH connection to your instance

posted Jun 5, 2016, 9:53 PM by Joseph Anthony Hermocilla   [ updated Oct 14, 2016, 4:10 AM by SRGICS UPLB ]
First, to escape from a frozen ssh session, press and release (excluding the brackets) [ENTER], [~], [.] in succession.

On the client machine and on the instance, set the mtu of the interface to 1454 bytes.

$sudo ifconfig eth0 mtu 1454

If the above steps did not work, try the following.

On your instance edit /etc/ssh/sshd_config then add the following lines at the end.
ClientAliveInterval 60 TCPKeepAlive yes ClientAliveCountMax 10000
Restart sshd then exit the session.

$sudo service ssh restart
$exit

On your client (machine you are connecting from), edit /etc/ssh/ssh_config then add the line below.
ServerAliveInterval 60
Reconnect again.

Lastly, if you are using gnome-terminal, set the custom command in Edit->Profile Preferences to the following.

env TERM=xterm /bin/bash

It is highly recommended to use screen after login.