0

I can establish an SSH tunnel using ssh -L 2222:<RDS-Endpoint>:5432 ec2-user@<EC2-IP> -i ~/.ssh/key.pem and then connect to my RDS using psql "host=localhost port=2222 user=postgres password=<pw>

These same settings in pgAdmin 4 do not seem to work.

  • Host name in connection tab = <RDS-Endpoint>
  • Tunnel host = <EC2-IP>
  • Port in connection tab = 5432
  • Port in SSH tunnel tab = 2222
  • Username in connection tab = postgres
  • Username in ssh tunnel tab = ec2-user
  • Password in connection tab = <pw>
  • And identity file in ssh tunnel tab = ~/.ssh/key.pem

After trying for a while pgAdmin 4 fails with: unable to connect to server: Failed to create the SSH Tunnel. Error: Could not establish session to SSH gateway

cat ~/.pgadmin/pgadmin4.log Just gives me:

ERROR   pgadmin:    Could not establish session to SSH gateway
Traceback (most recent call last):
  File "/usr/pgadmin4/web/pgadmin/utils/driver/psycopg3/server_manager.py", line 610, in create_ssh_tunnel
    self.tunnel_object.start()
  File "/usr/pgadmin4/venv/lib/python3.10/site-packages/sshtunnel.py", line 1331, in start
    self._raise(BaseSSHTunnelForwarderError,
  File "/usr/pgadmin4/venv/lib/python3.10/site-packages/sshtunnel.py", line 1174, in _raise
    raise exception(reason)
sshtunnel.BaseSSHTunnelForwarderError: Could not establish session to SSH gateway

I'm really lost on how to proceed given it works via the terminal. So clearly not some security group issue on AWS's side. I've tried deleting ~/.pgadmin and trying again, but same result. Any help appreciated thanx.

In case this helps:

lsb_release -a
No LSB modules are available.
Distributor ID: Pop
Description:    Pop!_OS 22.04 LTS
Release:    22.04
Codename:   jammy

1 Answer 1

0

You told it to ssh into port 2222, which is not correct. That would be like using -p 2222 on the ssh command line (which you did not do).

When pgadmin sets up the tunnel for you, it picks a large random number to use as the local rendezvous port number. You don't tell it what number to use, so there is nothing analogous to 2222 for you to enter.

2
  • After just leaving the Tunnel Port as 22 I have this issue: stackoverflow.com/questions/52235266/… I can solve it by running the tunnel in the terminal as the solution there suggests. I don't know how to fix it otherwise but since that is a different question I'll mark yours as correct here
    – Frikster
    Commented Sep 3, 2023 at 21:06
  • I solved all my issues immediately by switching to DBeaver
    – Frikster
    Commented Sep 3, 2023 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.