Bookmark and Share

How to SSH with tunneling.

Posted: Sunday, January 11th, 2009 at 4:28 amUpdated: Friday, January 30th, 2009 at 10:11 pm

MySQL runs on port 3306. You can choose any ports on your local computer (the computer you use to run PuTTY) as long as it’s not used yet. Valid port numbers are between 0 to 65535. However, I’d discourage using ports between 0 and 1000 as most reserved ports are assigned on that range. I like to use port 33306 as my forwarding port. I think it’s nice to just duplicate the first number thus easy to remember.

Since you want a local port 33306 to connect to server’s localhost on port 3306, type 33306 as source port, then localhost:3306 as destination. Then click on Add button. Make sure Local and Auto is selected. After clicking on Add button, your PuTTY configuration window should look like below.


One other thing that I normally do is to keep connection alive. PuTTY by default will not send a keep-alive packet and thus, SSH server will think it’s an idle connection and drops it after some time of inactivity. I often have periods of long inactivity and I don’t want the hassle of keep connecting. To set PuTTY so that it send keep-alive packet every some time, click on connections. I normally set the value to 60 as in the screen shot below.


Before you click on the Open button, make sure to back to the first screen by clicking Session on the left pane. Hit Save button then click on Open. You should then login to your server as usual. Once you are connected, you can fire up SQLYog and connect to your localhost at port 33306. It should be forwarded to server’s localhost port 3306 and you can use SQLYong as normal.

SSH Tunneling on Unix / Linux / FreeBSD / MacOS

On Unix or Unix like systems, open console. Then use regular ssh command as normal. Following our connection example above, here’s the command you’d use. Obviously change the username and the host.

user@laptop:~$ ssh -l username -L 33306:localhost:3306

I hope this article helps you. As always, I welcome comments / questions / critics that will help me and other readers understand better.

Pages: 1 2

Leave a Reply

− seven = 1