Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Ident authentication failed for user when connecting over TCP

ErrorFATAL: Ident authentication failed for user "postgres"

Short answer

A host line in pg_hba.conf uses method ident, so the server asked the client machine's ident service which OS user opened the connection, and the answer did not match the database user. Switch that line to scram-sha-256, or add a map, then reload.

  • Applies to PostgreSQL 16, PostgreSQL 17, Rocky Linux 9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See which pg_hba.conf line is chosen for a TCP connection. Look for the word ident in the method column.

    sudo -u postgres psql -c "SELECT line_number, type, database, user_name, address, auth_method FROM pg_hba_file_rules"
  2. 2Match what you see, then jump to its fix

    1. 1A line such as host all all 127.0.0.1/32 ident is the first matchThe matching host line uses identFix
    2. 2The ident service answers, but with a user name that is not the one requestedThe OS user and database user differ and no map existsFix
    3. 3The file already says scram-sha-256 and the error still names identYou edited pg_hba.conf but the server never re-read itFix

What does the error look like?

  • FATAL: Ident authentication failed for user "postgres"
  • psql: error: connection to server at "127.0.0.1", port 5432 failed: FATAL: Ident authentication failed for user "postgres"

Cause 1 of 3

The matching host line uses ident

1Check

Ident only works on TCP/IP. The server contacts an ident service on the client (RFC 1413, normally TCP port 113) and compares the answer with the database user. Without such a service, or with a different OS user name, it fails.

sudo grep -nE '^\s*host' "$(sudo -u postgres psql -Atc 'SHOW hba_file')"

2Fix

Change the method to scram-sha-256 and give the role a password. Use ident only on a closed network where you control every client.

# pg_hba.conf
host    all    all    127.0.0.1/32    scram-sha-256
host    all    all    ::1/128         scram-sha-256

# set a password for the role
sudo -u postgres psql -c "\password postgres"

3Verify

Reload, then connect over TCP and enter the password.

sudo -u postgres psql -c "SELECT pg_reload_conf()"
psql -h 127.0.0.1 -U postgres -d postgres -c "select 1"

Confirmed by postgresql.org

Did this fix it?

Cause 2 of 3

The OS user and database user differ and no map exists

1Check

Ident can translate names through a map= option backed by pg_ident.conf. Without one, the names must be identical.

sudo -u postgres psql -c "SHOW ident_file"

2Fix

Create a map entry and name it on the host line.

# pg_ident.conf   MAPNAME  OS-USER  DB-USER
webmap    www    appuser

# pg_hba.conf
host    appdb    appuser    192.168.1.0/24    ident map=webmap

3Verify

Reload and reconnect from that client.

sudo -u postgres psql -c "SELECT pg_reload_conf()"

Confirmed by postgresql.org

Did this fix it?

Cause 3 of 3

You edited pg_hba.conf but the server never re-read it

1Check

The server reads pg_hba.conf at start and on SIGHUP only. Compare what the server loaded with what is on disk.

sudo -u postgres psql -c "SELECT line_number, auth_method, error FROM pg_hba_file_rules"

2Fix

Reload the configuration.

sudo -u postgres psql -c "SELECT pg_reload_conf()"

3Verify

Repeat the failing connection.

psql -h 127.0.0.1 -U postgres -d postgres -c "select 1"

Confirmed by postgresql.org

Did this fix it?

How do I stop it coming back?

  • Prefer scram-sha-256 for every TCP line; use peer only for local socket admin logins.
  • Keep pg_hba.conf in version control or configuration management so edits are reviewed.
  • Run the pg_hba_file_rules query after each edit and fix any row with an error.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Databases

Peer authentication failed for user, on a local PostgreSQL connection

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "postgres"

A pg_hba.conf line with method peer only lets a local socket client in when its OS user name equals the requested database user.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.