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=100flag. With this flag, for every 100 seconds, the ssh client automatically sends a dump packet to keep the connection alive.
ssh -o ServerAliveInterval=100 email@example.com
- Method 2: In
Host my-host HostName example.com User user-name ServerAliveInterval 100
- Method 3: use
autosshcommand. Most of
autosshoptions are similar to of
autosshauto reconnects the
sshconnection for you under the hood.