Saturday, December 1, 2012

SSH tunneling and git

I can only connect to my lab's computers via a router. For simple stuff, this suffices:

homecomp:~ jdoe$ ssh jdoe@router.university.edu
[jdoe@router ~]$ ssh jdoe@labcomp

But this gets annoying for things like copying files. Fortunately, you can set up an SSH tunnel:

homecomp:~ jdoe$ ssh jdoe@router.university.edu -L 4321:labcomp:22

Here you are connecting to the router and also telling it to set up a tunnel from homecomp's local port 4321 to lapcomp port 22 (the default for ssh traffic). You can also add a -N flag (which stops you from running any commands through this terminal) and/or a -f flag (which makes this run in the background). I prefer not to use -f; this way it is easier to kill the tunnel should you need to.

And then you can do things like:

homecomp:~ jdoe$ ssh jdoe@localhost -p 4321

homecomp:~ jdoe$ scp -r -P 4321 jdoe@localhost:~/Documents ~/Desktop/workDocs

homecomp:~ jdoe$ git clone ssh://jdoe@localhost:4321/~/MATLAB

Yay!

No comments:

Post a Comment