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

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel