psql 没有提示我输入密码,然后拒绝访问

Dav*_*ave 6 postgresql permissions psql password

我在 Debian Linux 上使用 Postgres 9.4。我用一个用户创建了一个数据库,cindex可以访问该数据库。然而,当我尝试在命令行登录时,我什至没有提示输入密码:

myuser@myuserserver:~ $ psql -Ucindex cindex
psql: FATAL:  Peer authentication failed for user "cindex"
Run Code Online (Sandbox Code Playgroud)

我还需要做什么来启用用户?下面你可以看到我已经设置的权限:

postgres@myuserserver:~$ psql
psql (9.4.13)
Type "help" for help.

postgres=# GRANT SELECT ON ALL TABLES IN SCHEMA cindex TO cindex;
GRANT
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 cindex    | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =T/postgres          +
           |          |          |             |             | postgres=CTc/postgres+
           |          |          |             |             | cindex=c/postgres
 postgres  | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 |
 template0 | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 cindex    |                                                | {}
 postgres  | Superuser, Create role, Create DB, Replication | {}
Run Code Online (Sandbox Code Playgroud)

Cra*_*ger 7

对等认证

这意味着它使用的是 unix 套接字连接,并且 unix 套接字的连接设置为peerpg_hba.conf. 它只是检查 unix 用户名是否与请求的 postgres 用户名相同,而不关心密码。

如果您需要密码身份验证,请改用md5auth in pg_hba.conf

请参阅手册

PostgreSQL 在 SQL 配置和配置文件之间拆分身份验证的方式绝对令人困惑,因此您并不孤单。能够为用户设置密码,但在某些情况下忽略该密码并在其他情况下使用该密码,需要一些时间来适应。一旦你理解了系统,它就有意义,但它绝对不是可发现的和直观的。