This guide will walk you through the steps needed to setup an SSH tunnel from a Windows machine using PuTTY. You can download PuTTY here. An SSH tunnel is useful for port-forwarding, in the case of connecting securely to a remote database server.
If you're using Linux or Mac, it's probably easier to simply use the terminal (or Secure Shell program) that is already installed on your system.
RSA key
If you already have a private RSA key, you will need to convert it to ppk
format so that PuTTY can use it. To convert your RSA private key to this format you can use PuTTYgen (can be found here; search for "puttygen.exe" in that page). The program is simple enough to use, I don't think you'll have any problems with it.
If you do not yet have an RSA key pair (public and private), the above linked PuTTYgen tool can generate one for you.
Once you have your private RSA key as a ppk
file, you can move on to the next step.
Configure PuTTY
There are a few configurations that you must set precisely to get the SSH tunneling working with your RSA key.
First screen:
- Host Name (or IP address) - Set the host name equal to
USER@HOST
; whereUSER
is the user on the server with which you will be connecting andHOST
is the IP address or hostname of the server. - Close window on exit - This should be set to "Never". This allows you to debug the situation if a connection error occurs.
Next screen:
- Don't start a shell session or command at all - This should be checked.
Next screen:
- Click the Browse button and select the
ppk
file that you generated earlier.
Next screen:
- Add new forwarded port:
- Source port - the port number on your local machine which all requests to will be forwarded through the SSH tunnel to the remote server.
- Destination - the host and port number on the remote server to which requests will be forwarded. In this case,
localhost:3306
which is where a remote server's MySQL server is listening. - Don't forget to click the Add button.
That's it! It might be a good idea to save the configurations you've set so that you can easily go back and change things if you need to debug a problem. To save your configurations:
- Go back to the main screen
- Give your session a name
- Save
Try Connecting
Now that everything is configured, try to click the Open button to initialize the connection to the server. You should see a black terminal window open up. Something like this:
To open the logs view, like shown above, you right-click the title bar of the window and click the menu item called Event Log.