I’m trying to connect on my computer to a PostgreSQL database which is only accessible on some server (db allows only local connections). I thought I could use port forwarding like this:
$ ssh someserver.com -L 5100:127.0.0.1:5432
and then connect to the database like this:
$ psql -h 127.0.0.1 -p 5100 -U postgres dbname
However, the problem is that on the server there is no password, but when I try to connect to the forwarded port it asks me for a password. When I leave it empty it returns “psql: fe_sendauth: no password supplied” and doesn’t let me connect.
What could be the reason? I have also a PostgreSQL instance on my computer, could this cause some conflicts?
When you say that the db allows only local connections: you need to distinguish between “unix socket” connections and “TCP to localhost” connections, which are not the same thing and may be treated quite differently.
To test: on the database server, see if adding
-h 127.0.0.1onto the psql commandline makes a difference in whether you can connect or not.The rules for whether a password is required or not are in
pg_hba.conf. It might be that your database server is set to use “ident” authentication for unix (“local”) connections, so your Unix username is automatically accepted as the database username. Since that authentication method isn’t generally available for TCP/IP (“host”) connections, you have to use some other method- if it is set to “md5”, then it will require a password.Probably all you have to do is set a password for your user account on the database while connected locally:
ALTER USER username PASSWORD 'password'. If you want to avoid being prompted for a password all the time when connecting remotely, write a.pgpassfile to store it in your client user account: http://www.postgresql.org/docs/9.0/interactive/libpq-pgpass.html