It usually happens that the ssh connection suddenly hangs after left for awhile. This is because the ssh server is configured to disconnect the connection if nothing is sent from the client.

To make the connection stay alive forever. Use the following methods.

  • In the ssh command, add -o ServerAliveInterval=100 flag. With this flag, for each 100 second, the ssh client automatically sends a dump packet to keep the connection alive.
ssh -o ServerAliveInterval=100
  • In .ssh/config.
Host my-host
	User user-name
	ServerAliveInterval 100