reverse ssh connections
Setting up a reverse ssh connection can be useful when the destination machine is inside a NAT, and a port cannot be forwarded to it (eg, a work LAN), but an ssh in the reverse direction is possible.
Because the destination machine must set up the reverse connection automatically, the autossh utility can be used to keep the ssh connection alive so that it doesn't time out. From the destination machine:
The client-ssh-port is the port on the client machine used for incoming ssh connections (this parameter can be omitted if it is the standard port 22). The reverse-ssh-port is the port that is to be used when connecting back down the reverse connection from the client. From the client machine:
For systems where the client is not always available, it can be useful to put the autossh line in a cron entry, so that it will restart if the ssh exits on a connection error (for this to work requires a passwordless ssh login):
Because the destination machine must set up the reverse connection automatically, the autossh utility can be used to keep the ssh connection alive so that it doesn't time out. From the destination machine:
Code:
autossh -f -p client-ssh-port -R reverse-ssh-port:localhost:22 client-ip -fN
Code:
ssh -p reverse-ssh-port localhost
Code:
0 * * * * if ! ps -C autossh >/dev/null; then autossh-command; fi
Total Comments 0