Make ssh connection alive permanently

Make ssh connection alive permanently

It usually happens that the ssh connection suddenly hangs after left for a while. 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 seconds, the ssh client automatically sends a dump packet to keep the connection alive.
ssh -o ServerAliveInterval=100 user@example.com
  • In .ssh/config.
Host my-host
	HostName example.com
	User user-name
	ServerAliveInterval 100