Connecting to PostgreSQL via SSH Tunneling
In the event that you don't want to open port 5432 to any traffic, or you don't want to configure PostgreSQL to listen to any remote traffic, you can use SSH Tunneling to make a remote connection to the PostgreSQL instance. Here's how:
- Open PuTTY. If you already have a session set up to connect to the
EC2 instance, load that, but don't connect to it just yet. If you
don't have such a session, see this post.
- Go to Connection > SSH > Tunnels
- Enter 5433 in the Source Port field.
- Enter 127.0.0.1:5432 in the Destination field.
- Click the "Add" button.
- Go back to Session, and save your session, then click "Open" to
connect.
- This opens a terminal window. Once you're connected, you can leave
that alone.
- Open pgAdmin and add a connection.
- Enter localhost in the Host field and 5433 in the Port field.
Specify a Name for the connection, and the username and password.
Click OK when you're done.