我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。
我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:
psql: FATAL: Ident authentication failed for user "postgres"
现在有人知道如何解决这个问题吗?
我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。
我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:
psql: FATAL: Ident authentication failed for user "postgres"
现在有人知道如何解决这个问题吗?
当前回答
问题仍然是pg_hba.conf文件。这一行:你可以在/etc/postgres/ vary /main目录下找到这个文件
local all postgres peer
Should be
local all postgres md5
下面是官方PostgreSQL文档中关于身份验证方法的两个选项的简要描述。
对等的身份验证
对等身份验证方法的工作原理是从内核获取客户机的操作系统用户名,并将其用作允许的数据库用户名(可选的用户名映射)。此方法仅在本地连接上受支持。
密码身份验证
基于密码的认证方式有md5和password。除了通过连接发送密码的方式(分别为md5散列和明文)外,这些方法的操作类似。
如果您完全担心密码“嗅探”攻击,那么首选md5。尽量避免使用简单的密码。但是,md5不能与db_user_namespace特性一起使用。如果连接受SSL加密保护,则可以安全地使用密码(如果依赖于使用SSL,则SSL证书身份验证可能是更好的选择)。
修改此文件后,不要忘记重新启动PostgreSQL服务器。如果你在Linux上,那将是sudo service postgresql重启。
其他回答
如果你做了所有这些,它仍然不工作,检查该用户的到期:
Postgres密码认证失败
您得到这个错误是因为您没有通过客户端身份验证。根据错误消息,您可能有默认的postgres配置,它将所有PostgreSQL连接的客户端身份验证方法设置为“IDENT”。
你一定要阅读PostgreSQL手册中的19.1节客户端身份验证,以更好地理解可用的身份验证设置(对于pg_hba.conf中的每条记录),但下面是相关的代码片段,以帮助解决你遇到的问题(来自版本9.5手册):
trust Allow the connection unconditionally. This method allows anyone that can connect to the PostgreSQL database server to login as any PostgreSQL user they wish, without the need for a password or any other authentication. See Section 19.3.1 for details. reject Reject the connection unconditionally. This is useful for "filtering out" certain hosts from a group, for example a reject line could block a specific host from connecting, while a later line allows the remaining hosts in a specific network to connect. md5 Require the client to supply a double-MD5-hashed password for authentication. See Section 19.3.2 for details. password Require the client to supply an unencrypted password for authentication. Since the password is sent in clear text over the network, this should not be used on untrusted networks. See Section 19.3.2 for details. gss Use GSSAPI to authenticate the user. This is only available for TCP/IP connections. See Section 19.3.3 for details. sspi Use SSPI to authenticate the user. This is only available on Windows. See Section 19.3.4 for details. ident Obtain the operating system user name of the client by contacting the ident server on the client and check if it matches the requested database user name. Ident authentication can only be used on TCP/IP connections. When specified for local connections, peer authentication will be used instead. See Section 19.3.5 for details. peer Obtain the client's operating system user name from the operating system and check if it matches the requested database user name. This is only available for local connections. See Section 19.3.6 for details. ldap Authenticate using an LDAP server. See Section 19.3.7 for details. radius Authenticate using a RADIUS server. See Section 19.3.8 for details. cert Authenticate using SSL client certificates. See Section 19.3.9 for details. pam Authenticate using the Pluggable Authentication Modules (PAM) service provided by the operating system. See Section 19.3.10 for details.
所以…要解决您正在经历的问题,您可以执行以下操作之一:
Change the authentication method(s) defined in your pg_hba.conf file to trust, md5, or password (depending on your security and simplicity needs) for the local connection records you have defined in there. Update pg_ident.conf to map your operating system users to PostgreSQL users and grant them the corresponding access privileges, depending on your needs. Leave the IDENT settings alone and create users in your database for each operating system user that you want to grant access to. If a user is already authenticated by the OS and logged in, PostgreSQL won't require further authentication and will grant access to that user based on whatever privileges (roles) are assigned to it in the database. This is the default configuration.
注意:pg_hba.conf和pg_identity .conf的位置取决于操作系统。
在pg_hba.conf中设置正确了吗?
参见https://ubuntu.com/server/docs/databases-postgresql如何做。
解决这个问题的一个方法是编辑pg_hba.conf
sudo vi /etc/postgresql/9.3/main/pg_hba.conf
暂时
# Database administrative login by Unix domain socket
local all postgres trust
至此,您就完成了。为了安全,那就去吧
sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'your_password';
然后返回,将pg_hba.conf设置为
# Database administrative login by Unix domain socket
local all postgres md5
我只需要简单地添加-h localhost位就可以工作了