Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How connect with postgres using ssh tunnel?

How I can connect with my database via ssh tunnel? Link for ssh tunnel look like:

postgresql+ssh://sshUser:sshPassword@sshServerUrl/dbUser:dbPassword@dbUrl:dbPort/dbName

Can Prisma handle this format?

like image 354
mxcdh Avatar asked Jan 25 '26 11:01

mxcdh


1 Answers

If you can connect to the database machine through ssh, do so first.

ssh -L 5432:localhost:5432 database-machine.org

This makes an assumption your database listens on localhost on your server and listens to port 5432. Also makes an assumption you have a free port 5432 on your machine.

So, how it works: the first 5432 on the string is the port you open on localhost, the middle part localhost means the hostname the PostgreSQL is listening to (can also be 127.0.0.1 or 0.0.0.0) and the last number is the port the server is listening to.

When you get this running, from the same machine you can modify your connection string to:

postgresql://user:pass@localhost:5432/database

And it should work.

like image 55
Nurul Sundarani Avatar answered Jan 28 '26 00:01

Nurul Sundarani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!