Skip Links

Network World

IT Asked & Answered

AdviceGadgetsToolsITAA Home

Use PC client to manage database behind firewall

Average: 4 (1 vote)

I work with a PostgreSQL database that sits behind two SSH logins. The first machine is accessible from the Internet. The second machine is accessible only by SSH and only from the first machine. How can I tunnel through SSH all the way to the database server so that I can manage the database using PGAdminIII from my PC?

Blass
Answer by Steve Blass

Expert's answer

Using a command line SSH client like the one provided by MinGW or Cygwin you can accomplish your goal by first creating a tunnel through the first web facing server to the database server and then creating a second connection going through the first tunnel that establishes a tunnel connecting the PostGreSQL network port on your PC to the PostGreSQL port on the database server. Using two command windows and two separate SSH connections utilizing the -L flag to tunnel local ports the connection could be made in the following way.

First build a tunnel connecting some port, say 43, on the local PC to the SSH port 22 on the database server through the webserver using the command

ssh -l webusername -L 43:databaseserver:22 webserver

After logging in to the webserver open a second command window on the PC and build a tunnel connecting the local PostGreSQL port 5432 to that same port number on the database server by going through the first tunnel we built connecting local port 43 to database server port 22 by using the command

ssh -l dbusername -p43 -L 5432:localhost:5432 localhost

This creates an SSH connection to port 43 on our local PC (localhost) which connects to port 22 on the databaseserver (which calls itself as localhost) to make a tunnel through that first connection to connect port 5432 on the PC to port 5432 on the database server.

Now when the PGAdminIII database management utility on the PC connects to the local PostGreSQL port it will be directly connected to the database on the remote server.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You can use BBCode tags in the text.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <p> <strong> <i> <br /> <br> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Welcome, visitor. Register Log in
What's IT Asked & Answered?

youASK weANSWER peersDISCUSS

The IT community benefits from the shared knowledge

'); ?>