Page Tools:
Wiki Relationships:
Admin Tools:
Digging Tunnels with ssh
The great thing about ssh is that it is very simple to access a machine either through a client like putty on Windows or the command line ssh tools on Unix or Linux. Normally the next task you may experience is to try is to get a password-less login by generating a public key on your local machine that you place on the server. Normally for access to services like a subversion repository. However there is a lot more you can do with ssh particularly hopping or tunnelling from one machine to another. This article covers some of the basic tunnelling options
For this first example I will show how you can access a database, postgres, that resides on a machine which is only accessible by a gateway machine, called my-gateway. Here is a simple picture to explain the setup
First let's get our ssh tunnel created. I'm using the windows program called putty.exe, pre-compiled versions can be downloaded here.
One putty.exe is started you will see the session window
Enter the gateway machine in the hostname field, this is the machine that you will need to login in to get to your remote database. I've entered my-gateway with the default ssh port.
Before we go too much further let's create a name for that session, I chose the name tunnel, and enter it in the saved session box on right and hit save
Expand the Connection->SSH menu on the left see note (1).
You should see the values Kex, Auth and the one we are interested in called Tunnels note (2). Selecting Tunnels should open up the port forwarding screen as shown. I chose a local port 9999, feel free to chose any port you want. Next enter the database machine that is accessible via the gateway with its port. port 5432 which is standard postgres that the database is listening too. so my-db:5432 Then click add. Finally return to the session window as seen in Figure 1, top item in the left list and click save. You can now open the connection. Click Open and enter the username and login to get into the gateway and keep this window open.
Now to connect from a windows side to the postgres database I need to add an odbc connector. Search for odbc postgres or click on this link
I then go to control panel->administration tools->Data sources (odbc). You can create a user or system datasource name, I chose system. click on add, select PostgreSQL Unicode or ANSI from the driver list. Enter your postgres db instance name to connect too, eg template1. Enter the server name localhost and the port you chose for the tunnel, eg 9999. Finally enter the login and password for the database and click test and finally save.
Now to access your remote database click on your putty.exe and load your tunnel session, login and keep that window open and select the odbc name in your application, whether its excel or sqlserver report server.
Most Recent |
Most Popular |
Most Active Categories |
| Back To Top | Add New Article | Printable Page |





Testing
