2017-10-12 78 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