2017-10-12 76 views
0

PostgreSQL的10.0,Ubuntu的16.04MD5认证本地用户

我想用户在本地主机与密码登录。 为此,我将md5的规则移至顶端。

SHOW hba_file;

postgres=# # TYPE DATABASE  USER   ADDRESS     METHOD 
postgres-# 
postgres-# # IPv4 local connections: 
postgres-# host all    all    127.0.0.1/32   md5 
postgres-# # "local" is for Unix domain socket connections only 
postgres-# local all    all          peer 
postgres-# # IPv6 local connections: 
postgres-# host all    all    ::1/128     md5 
postgres-# # Allow replication connections from localhost, by a user with the 
postgres-# # replication privilege. 
postgres-# local replication  all          peer 
postgres-# host replication  all    127.0.0.1/32   md5 
postgres-# host replication  all    ::1/128     md5 

然后重新启动该服务:

sudo service postgresql restart 

问题:

[email protected]:~$ psql -U admin -W 
Password for user admin: 
psql: FATAL: Peer authentication failed for user "admin" 

你能告诉我为什么我的MD5设置不起作用?

回答

0

manual page for psql状态:

如果省略主机名,psql将通过Unix域套接字连接到服务器的本地主机上,或者通过TCP/IP到本地主机上的机器,不要”没有Unix域套接字。

所以,如果你的服务器上的域套接字和TCP/IP上听,你可以将这个连接会local类型上the pg_hba.conf manual page解释。

因此,它会匹配这一行:

local all    all          peer 

这将尝试使用"peer authentication", as described here

您应该:

  • 更改该行要求对本地(域套接字)连接md5认证。
  • 使用-h 127.0.0.1/--host 127.0.0.1指定psql命令中的主机名,以强制使用TCP/IP。
  • 通过将unix_socket_directories设置为空字符串来完全禁用Unix域套接字,如described in the configuration section of the manual