Thursday, October 13, 2011

SSH Tunnel example

The steps below are intended to be used in a scenario where the user has an account on all three systems.  The systems are: mysystem, host-not-blocked and host-behind-firewall.  The user can ssh from mysystem to host-not-blocked and the user can ssh from host-not-blocked to host-behind-firewall, but not from mysystem to host-behind-firewall because of a firewall of some sort.   The example show how a ssh tunnel can be used to allow the user to ssh from mysystem to host-behind-firewall. Enjoy!!!

Step 1) Screen (optional but recommended)

Log on to mysystem and execute screen

Step 2) Create Tunnel

On mysystem execute :

redcricket@mysystem:~$ ssh -L 2022:host-behind-firewall:22 host-not-blocked
Password:
...
redcricket@host-not-blocked:~$

Now detach ^A^D (if you are using screen.  If not you will need to start up a terminal.)
Why port 2022? Well if I had used port 22 I would have gotten an error message about how that port number is reserved for the 'root' user, so I pick 2000 + 22 = 2022.
Step 3) Use the tunnel

On mysystem execute:
redcricket@mysystem:~$ ssh -p 2022 localhost
...
redcricket@host-behind-firewall:~$

TIP For getting files matching *.uniq off of host-behind-firewall I have this cronjob.

*/15 * * * * scp -P 2022 localhost:"*.uniq" /users/redcricket/tasks/LOGS/host-behind-firewall && ssh -p 2022 localhost "rm *.uniq" > /dev/null 2>&1

No comments:

Post a Comment