![Forrest logo](/images/logo.png)
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 machine
This command is using the autossh tool to establish a secure tunnel between a local machine and a remote server.
Here is the breakdown of each option:
-f
: This option runs autossh in the background.-M 0
: This option disables the monitoring port. Normally, autossh uses a port to monitor the connection, but setting it to 0 disables this feature.-N
: This option tells autossh not to execute any remote commands. It is used when you only need to establish the connection without running any specific commands on the remote server.-o "ServerAliveInterval 10"
: This sets the interval (in seconds) at which autossh sends keep-alive messages to the server to check if the connection is still active.-o "ServerAliveCountMax 3"
: This sets the maximum number of keep-alive messages that can be sent without receiving any response before considering the connection as inactive.-o ExitOnForwardFailure=yes
: This option tells autossh to terminate the connection if it fails to set up the specified port forwarding.-L ${local_port}:localhost:${remote_port}
: This sets up local port forwarding. Any traffic sent tolocalhost:${local_port}
on the local machine will be forwarded tolocalhost:${remote_port}
on the remote server.${user}@${host}
: Specifies the user and the hostname (or IP address) of the remote server to connect to.
In summary, this command establishes a persistent SSH tunnel and forwards local traffic from ${local_port}
to the remote ${remote_port}
on the ${host}
machine, using the SSH credentials for ${user}
. The ServerAliveInterval
and ServerAliveCountMax
options ensure the connection stays active, and ExitOnForwardFailure
terminates the connection if the port forwarding fails.
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.