How to connect to Postgresql database with ssh-tunnel with client

I have setup ssh connexion to my droplet, I have root user and non-root with privilege user. All is working fine.

I have setup a postgresql database and create a db owned by the non-root user. If I’m login with this user, I can log to the database.

Now I want to use PgAdmin4 or DBeaver to access this db with a UI than with terminal. I want to use SSH Tunnel for security reason. But nothing I trying is working…

I setup my SSH Tunnel with

ssh -L 5432:

Both pgadmin and dbeaver can’t login to the database.

Thanks :)

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
December 12, 2022

Hi there,

Indeed, it should work as follows:

ssh -L 5432: user@your_ip_address

However, note that if you have Postgres running locally on your laptop and it is already listening on port 5432, then you should use a different local port, eg:

ssh -L 5433: user@your_ip_address

The syntax itself is as follows:

ssh -L [local_addr:]local_port:remote_addr:remote_port [user@]sshd_addr

Hope that this helps!



After some test and research, I try to change the port number from 5432 to 22 that is the port for SSH in the setting and it’s work !

Absolutely not easy to understand the field “port” in ssh is different than in general setting

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.