Forrest logo
back to the autossh tool

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 machine

This command is used to establish an SSH tunnel between a local and remote machine using the autossh tool.

Here's a breakdown of the command:

  • autossh: It is a program that automatically restarts SSH sessions and tunnels. It is similar to the regular ssh command, but it provides a mechanism to automatically reconnect and resume the session in case of disconnections.
  • -M ${monitor_port}: This option specifies the port number to use for the monitoring connection. It is used by autossh to detect if the SSH session is still active. If the monitoring connection is lost, autossh will automatically attempt to reconnect.
  • -L ${local_port}:localhost:${remote_port}: This option establishes a local port forwarding. It means that any traffic sent to the ${local_port} on the local machine will be forwarded to localhost:${remote_port} on the remote machine. This allows you to access services running on the remote machine through the ${local_port} on your local machine.
  • ${user}@${host}: This specifies the username (${user}) and hostname (${host}) of the remote machine to connect to using SSH.

To summarize, this command sets up a persistent SSH tunnel between a local and a remote machine, forwarding traffic from the ${local_port} on the local machine to the ${remote_port} on the remote machine. The autossh tool is used to automatically manage reconnection in case of failures.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the autossh tool