我已经在我的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
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
其他回答
编辑/etc/postgresql/8.4/main/pg_hba.conf文件,并将ident或peer替换为md5或trust,这取决于您是否希望它在您自己的计算机上询问密码。 然后重新加载配置文件:
/etc/init.d/postgresql reload
问题仍然是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重启。
解决这个问题的一个方法是编辑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
在我的情况下,解决方案是:(给关心的人) 登录postgres:
sudo -i -u postgres
psql
ALTER USER postgres WITH PASSWORD 'postgres'; # type your password here
问候
我花了更多的时间来解决这个我愿意承认的错误。
我认为pg_hba.conf中的身份验证配置顺序与您的情况相关。默认配置文件在普通安装中包含几行。这些默认值可以匹配身份验证尝试的条件,从而导致身份验证失败。不管在.conf文件末尾添加了什么额外的配置,它都会失败。
要检查使用的是哪一行配置,请确保查看消息的默认日志文件。你可能会看到这样的东西
LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL: Ident authentication failed for user "acme"
DETAIL: Connection matched pg_hba.conf line 82: "host all all 127.0.0.1/32 ident"
结果是这条默认行导致了拒绝。
host all all 127.0.0.1/32 ident
试着把它注释掉。