用于 Postgres 身份验证的 ident 与 md5

ident vs md5 for Postgres authentication

我在 CentOS 上设置了一个 Postgres 数据库服务器并创建了一个数据库,mydb

我以系统用户 postgres 访问 psql 并检查它是否存在:

$ sudo -u postgres -i
$ psql
postgres=# \l

 Name | Owner | ...    
--------------------
 mydb | postgres | ... 

我接着配置:

(1) listen_addresses = 'localhost'postgresql.conf 中取消注释。

(2) 我为用户 postgres.

设置了密码
sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'my_password';

但是,通过 psql -U postgres -h localhost 和 Pgadm3 的连接失败并出现此错误:

Ident autentication failed for user "postgres"

我检查了/var/lib/pgsql/9.4/data/pg_hba.conf

ident 是本地 IPv6IPv4 连接的默认方法。

我将其从 ident 更改为 md5

然后,通过 Pgadmi3 和 psql 的连接按预期工作

为什么 ident 失败?

由于以下原因失败:

The ident authentication method works by obtaining the client's operating system user name from an ident server and using it as the allowed database user name (with an optional user name mapping). This is only supported on TCP/IP connections.

ident 应该表示 UNIX 标识。为了 ident 工作,你必须 运行 psqlPGAdminpostgres 用户(CentOS 上的默认 Postgres 进程所有者)。因此,请确保您制作了 sudo su - postgressudo - postgres(并且它如您所示那样工作)。

md5其实就是md5哈希密码识别。对我个人而言,这是最简单的方法。

我确信在您的示例中一切正常:-)