can not connect via SSH to a remote Postgresql database

Solution 1:

In my case, the problem was that the tunnel ended in an IPv6 address:

ssh -L 5434:localhost:5432 user@server

It was enough to replace localhost with the address I had assumed was previously used:

ssh -L 5434:127.0.0.1:5432 user@server

15 minutes of my life down the drain. :) Hope this spares someone else's time...

Solution 2:

Check if the remote host allow tunneling. You can check with the client if the tunnel is refused with:

ssh -v -L 3333:myHost:5432 myUser@myHost

Solution 3:

Sounds like you need to add permissions for your user to access postgresql non-locally.

I know it seems that by creating the tunnel, you're connecting locally, but you probably aren't accessing it by loopback/localhost.

You likely need to add a line to pg_hba.cong i would give an example, but i'm on my phone, sorry


Solution 4:

If someone is still looking for solution:

Try to set in /etc/ssh/sshd_config:

AllowTcpForwarding yes
GatewayPorts yes

then:

service sshd restart

Tags:

Postgresql

Ssh