LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > neonsignal
User Name
Password

Notices


Rate this Entry

reverse ssh connections

Posted 05-23-2011 at 05:01 AM by neonsignal
Updated 05-23-2011 at 05: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:
Code:
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:
Code:
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):
Code:
0 * * * *  if ! ps -C autossh >/dev/null; then autossh-command; fi
Posted in Uncategorized
Views 936 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:31 PM.

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