postgresql - 如何配置 postgresql 使其接受登录名+密码身份验证?

标签 postgresql ubuntu

我安装了全新的 ubuntu 10.10,其中包含所有更新和 postgresql 8.4
为了让 postgresql 接受登录名+密码连接,我通过以下方式配置了它:

sudo su postgres
psql
ALTER USER postgres WITH PASSWORD 'password';
CREATE DATABASE myapp;
\q
exit
sudo vi /etc/postgresql/8.4/main/pg_hba.conf
change "local all all indent" to "local all all trust"

但是,令人惊讶的是,这不起作用!命令

psql -U postgres password

计算错误:

psql: FATAL:  Ident authentication failed for user "postgres"

有什么提示可以让 psql -U 正常工作吗?

最佳答案

为“postgres”用户保留身份验证可能是个好主意。默认情况下,我相信 Ubuntu 使用“postgres”用户来执行升级、备份等,这要求它能够在没有指定密码的情况下登录。

我建议创建另一个用户(可能使用您自己的用户名)并赋予其管理员权限。然后您可以在本地连接上使用该用户和密码。

这是我的 pg_hba.conf 的相关部分:

# allow postgres user to use "ident" authentication on Unix sockets
# (as per recent comments, omit "sameuser" if on postgres 8.4 or later)
local   all   postgres                         ident sameuser
# allow all other users to use "md5" authentication on Unix sockets
local   all   all                              md5
# for users connected via local IPv4 or IPv6 connections, always require md5
host    all   all        127.0.0.1/32          md5
host    all   all        ::1/128               md5

另请注意,psql -U postgres password 不会执行您想要的操作。绝不能在命令行中指定密码。这将尝试以用户“postgres”身份登录名为“password”的数据库。

您应该改用 psql -U postgres myapp。如果 Postgres 正确配置为需要密码,它将自动提示您输入密码。

如果我们希望自动填写密码,place it in $HOME/.pgpass file

关于postgresql - 如何配置 postgresql 使其接受登录名+密码身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4328679/

相关文章:

postgresql - Postgres/PGAdmin 导出空 CSV

ubuntu - 启用 mod_rewrite ubuntu

ubuntu - SublimeLinter 无法确定 shell PATH

bash - 将命令传递给 Bash 中的函数

ruby-on-rails - Net::SSH::AuthenticationFailed:用户身份验证失败

Linux X session 脚本

postgresql - 我如何在 postgres 中返回一点

.net - 将 string[][] 与 npgsql 一起使用

django - 在 Django 模型中设置主键起始值

c# - 当无法找到请求的 PostgreSQL 表时,如何捕获异常并使用错误代码?