autossh
Autossh is a command line tool used for automatically establishing and maintaining secure shell (SSH) connections. It is particularly useful in scenarios where we need to maintain a stable and reliable SSH tunnel or connection, even in cases of intermittent network disruptions or when the connection drops unexpectedly.
Typically, when an SSH connection is terminated, we would need to manually reconnect and reconfigure the tunnel. However, autossh helps automate this process by monitoring the SSH connection and automatically attempting to reconnect when necessary.
Autossh achieves this by running an instance of SSH in the background and actively monitoring the connection. If the connection drops, autossh will immediately initiate a new connection, using the same parameters specified in the initial SSH command. It can be configured to utilize specific ports, forward local or remote ports, and handle other SSH options like keys or passwords.
In addition to providing the automatic connection management functionality, autossh also includes features such as connection monitoring, keep-alive probes, and the ability to handle multiple connections simultaneously.
Overall, autossh is a useful tool for ensuring the resilience and continuous operation of SSH connections, making it a popular choice for scenarios like remote system administration, tunneling, or establishing secure communication channels.
List of commands for autossh:
-
autossh:tldr:491a3 autossh: Start an SSH session, restarting when a monitoring port fails to return data.$ autossh -M ${monitor_port} "${ssh_command}"try on your machineexplain this command
-
autossh:tldr:4ddc4 autossh: Run in the background, with no monitoring port, and instead send SSH keep-alive packets every 10 seconds to detect failure.$ autossh -f -M 0 -N -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" "${ssh_command}"try on your machineexplain this command
-
autossh:tldr:74784 autossh: Fork `autossh` into the background before executing `ssh` and don't open a remote shell.$ autossh -f -M ${monitor_port} -N "${ssh_command}"try on your machineexplain this command
-
autossh:tldr:cf0d0 autossh: Forward a local port to a remote one, restarting when necessary.$ autossh -M ${monitor_port} -L ${local_port}:localhost:${remote_port} ${user}@${host}try on your machineexplain this command
-
autossh:tldr:f3a46 autossh: Run in the background, with no monitoring port and no remote shell, exiting if the port forward fails.$ autossh -f -M 0 -N -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -o ExitOnForwardFailure=yes -L ${local_port}:localhost:${remote_port} ${user}@${host}try on your machineexplain this command