Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Blogs > neonsignal
User Name


Rate this Entry

reverse ssh connections

Posted 05-23-2011 at 06:01 AM by neonsignal
Updated 05-23-2011 at 06:06 AM by neonsignal

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:
autossh -f -p client-ssh-port -R reverse-ssh-port:localhost:22 client-ip -fN
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:
ssh -p reverse-ssh-port localhost
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):
0 * * * *  if ! ps -C autossh >/dev/null; then autossh-command; fi
Posted in Uncategorized
Views 713 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 05:00 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration