How to set up a ssh tunnel

First, setting up a tunnel is fairly easy. Second, for some reason I can never seem to get it right. Talking to other geek friends, even those smarter than me -- there seem to be quite a few, if you ask them -- it seems everyone has problems with it. So here's the shortcut:


Start by opening the tunnel. Specify the port locally, and the port to which you are going to connect:
ssh -L 3307:localhost:3306 dummy@www.inevergetitright.com

-L is the instruction to listen at port 3307

3307 is the port you have opened locally for the tunnel

localhost - that's you

3306 is the port opened at inevergetitgright

dummy is the user recognized on the inevergetitright server

Suppose you are doing this to set up a mysql connection on the remote server. All you do is open mysql in the normal way, but specify a port:

mysql -u asdfsd -p -P 3307 -h 127.0.0.1

Note that you have to specify 127.0.0.1. "localhost" won't work!

No comments:

Post a Comment