0

I've the following:

  • Amazon Linux 2
  • Postgres 12 installed a user created

I'm using ssh to connect to my instance.

The issue is that it doesn't let me to connect to my postgres database. I've created a user using something like:

create user myuser with encrypted password 'strongpassword';

and postgres server is running ok, but when i try to connect to my db it throws:

$: psql -h localhost --port 5432 --password -U myuser -d mydb    

psql: error: FATAL:  Ident authentication failed for user "myuser"

I don't know why it doesn't recognize my user.

Thanks in advance


Update

enter image description here

1 Answers1

2

**You'll have to add your user to pg_hba.conf and specify the network cidr in your entry.

The entries follow this format:

TYPE DATABASE USER ADDRESS METHOD

Here's an example for a local connection using md5 (you have to specify the loopback address as a /32):

local   myuser        all             127.0.0.1/32         md5

**Here's an example allowing a connection on the same class A network (you can always expand or restrict the CIDR more appropriately depending on your needs for the hosts that will be accessing your postgres server):**
host    all             myuser       10.10.0.0/24          md5

Then reload postgres: systemctl reload postgresql

After that, you should then be able to log in.

EWJ00
  • 136
  • 3
  • Hmm it doesn't work. I've updated my question why an screenshot maybe i'm using the wrong address. I want to connect from my EC2 to my PostgreSQL that is installed in the same EC2. Thanks in advance – Pablo Pantaleon Apr 07 '21 at 23:26
  • for your pg_hba.conf you can change your `host all all 127.0.0.1/32 ident` to `host all all 127.0.0.1/32 md5` – EWJ00 Apr 08 '21 at 01:12
  • you can also do the same thing for your 3rd entry for ipv6 or comment it out if you arent going to be connecting via ipv6 (the one that has `:1/128` – EWJ00 Apr 08 '21 at 01:14