I'm trying to log in by passing the host's IP as a parameter, simulating a login from outside:
root@ubuntu-2gb-nbg1-1:/etc/postgresql/12/main# psql -h YYY.YYY.YYY.YYY -p 5433 -d myproject -U myproject
Password for user myproject:
psql: error: FATAL: password authentication failed for user "myproject"
FATAL: password authentication failed for user "myproject"
I then try to log in from the same host with the same password but with different options:
root@ubuntu-2gb-nbg1-1:/etc/postgresql/12/main# psql -h localhost -U myproject -d myproject
Password for user myproject:
psql (12.6 (Ubuntu 12.6-0ubuntu0.20.04.1), server 10.16 (Ubuntu 10.16-0ubuntu0.18.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
myproject=>
I am using PostgreSQL 12 and trying to set up a remote login for a service which should write to the DB from the outside. I've already set up the listener in /etc/postgresql/12/main/postgresql.conf to also listen to my remote server and configured my /etc/postgresql/12/main/pg_hba.conf as follows:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all XXX.XXX.XXX.XXX/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
The problem I have is that when attempting to log in remotely, the password authentication fails. The same username and password is correct when logging in from within the host. It's very strange that the password is being rejected when attempting the remote login. Does anyone have any suggestions?