3 ways to make an ssh connection alive permanently

3 ways to make an ssh connection alive permanently

It usually happens that the ssh connection suddenly hangs after being 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.

  • Method 1: in the ssh command, add -o ServerAliveInterval=100 flag. With this flag, for every 100 seconds, the ssh client automatically sends a dump packet to keep the connection alive.
ssh -o ServerAliveInterval=100 user@example.com
  • Method 2: In .ssh/config.
Host my-host
	HostName example.com
	User user-name
	ServerAliveInterval 100
  • Method 3: use autossh command. Most of autossh options are similar to of ssh except that autossh auto reconnects the ssh connection for you under the hood.
Buy Me A Coffee