Linux

PostgreSQL Linux PAM 身份驗證錯誤

  • February 2, 2021

我在 Ubuntu 20.04.1 上使用 PSQL 版本 12.5。我的pg_hba.conf文件如下所示:

# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# 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
# PAM Authentication
host    all             all             0.0.0.0/0               pam
# IPv4 local connections:
host    all             all             127.0.0.1/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

我創建了一個 USER\Role :

CREATE USER test WITH LOGIN;

其中 test 是 Linux 使用者並且工作正常。但是當我執行時:

psql -U test 

我得到錯誤:

postgres@ubuntu2004:~$ psql -U test
psql: error: FATAL:  Peer authentication failed for user "test"

我錯過了什麼嗎?

由於您沒有指定該-h選項,PostgreSQL 通過本地 Unix 套接字連接。這由 中的local條目控制pg_hba.conf。因此,您通過“對等”身份驗證進行身份驗證。但是由於您不是作業系統使用者test,因此對等身份驗證失敗。

要獲得 PAM 身份驗證,請連接-h 127.0.0.1.

引用自:https://dba.stackexchange.com/questions/284491