如何配置 postgresql 使其接受登录+密码身份验证?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4328679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure postgresql so it accepts login+password auth?
提问by grigoryvp
I have a fresh ubuntu 10.10 install with all updates and postgresql 8.4
In order for postgresql to accept login+password connections i have configured it via:
我有一个全新的 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"
But, surprisingly, this is not working! The command
但是,令人惊讶的是,这不起作用!命令
psql -U postgres password
Evaluates with error:
错误评估:
psql: FATAL: Ident authentication failed for user "postgres"
Any hints how i can make the psql -U
to work?
任何提示我如何psql -U
才能工作?
回答by cecilkorik
It is probably a good idea to leave the "postgres" user with ident authentication. By default I believe Ubuntu uses the "postgres" user to perform upgrades, backups, etc, and that requires that it is able to login without a specified password.
让“postgres”用户进行身份验证可能是个好主意。默认情况下,我相信 Ubuntu 使用“postgres”用户来执行升级、备份等,这要求它能够在没有指定密码的情况下登录。
I recommend creating another user (probably with your own username) and giving it admin privileges as well. Then you can use that user with passwords on local connections.
我建议创建另一个用户(可能使用您自己的用户名)并为其授予管理员权限。然后您可以在本地连接上使用该用户的密码。
Here is what the relevant parts of my pg_hba.conf look like:
这是我的 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
Also note that psql -U postgres password
will not do what you want. The password should never be specified on the commandline. That will try to login as user "postgres" to a database named "password".
还要注意,psql -U postgres password
不会做你想做的。永远不应在命令行上指定密码。这将尝试以用户“postgres”的身份登录到名为“password”的数据库。
You should use psql -U postgres myapp
instead. Postgres will automatically prompt you for a password, if it is configured properly to require one.
你应该psql -U postgres myapp
改用。Postgres 会自动提示你输入密码,如果它被正确配置为需要密码的话。
In case we want the password be filled-in automatically, place it in $HOME/.pgpass file
如果我们希望自动填写密码,请将其放在 $HOME/.pgpass 文件中
回答by Max
I think your pg_ident.conf
file is misconfigured. Also, have you tried
我认为您的pg_ident.conf
文件配置错误。另外,你有没有试过
psql -U postgres -W
回答by elc
Another thing that can cause this is expired credentials. I don't think this happened in version 8, but in version 9 when you create a new role in pgadmin, it is created in an expired state and you need to change or clear the role's expiration date before you will be able to login with it.
可能导致这种情况的另一件事是凭据过期。我不认为这在第 8 版中发生,但是在第 9 版中,当您在 pgadmin 中创建新角色时,它会以过期状态创建,您需要更改或清除角色的过期日期,然后才能使用它。