Wednesday, October 21, 2009

TCP forwarding/ssh tunneling


zz from kartik mail
Here's a way to use ssh tunneling from outside department to avoid
logging in twice to reach osnet1.

Most of you should have an account on alpha.cs.binghamton.edu

We can tunnel our ssh connection to
osnet1.cs.binghamton.edu via alpha.cs.binghamton.edu
as follows

Assuming you are using UNIX there, first establish a tunnel
to osnet1 as follows:

$ ssh -f -L 2222:osnet1.cs.binghamton.edu:22 alpha.cs.binghamton.edu sleep 24h

When it asks for password, type your password
for alpha.cs.binghamton.edu.

This tells ssh to forward your local port 2222 via
alpha.cs.binghamton.edu to port 22 on
osnet1.cs.binghamton.edu

The -f places the above ssh command in background.
The "sleep 24h" just executes the sleep command for
a long time (24 hrs -- you can increase it to whatever you want)

Next, ssh to your local port 2222 as if you were doing an ssh to osnet1

$ ssh -p 2222 localhost

When it asks for password again, type your password for osnet1.

If you want to transfer files between your local machine and osnet1 then

$ scp -P 2222 localhost:

(note the capital P) .... and so on.

This should log you into osnet1. From osnet1 you can ssh to any
other machine in the lab.

If you set up you ssh keys properly on both alpha.cs and osnet1.cs
then you don't even have to type your password each time. Just place
the above two commands in a script and it'll seamlessly log you in.
(I can guide you through this if you don't know how).

Here's some more explanation of TCP forwarding using SSH

http://www.gsp.com/cgi-bin/man.cgi?section=1&topic=ssh#5

No comments:

Post a Comment