postgresql Postgres:尝试使用不同的 unix 用户登录时身份验证失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8420761/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:27:24  来源:igfitidea点击:

Postgres: authentication fails when try to login with different unix user

postgresqllogin

提问by daydreamer

I have a user hduserand user postgres,

我有一个用户hduser和用户postgres

with hduser:

hduser

hduser@master:/$ psql -Upostgres -W analytics
Password for user postgres: 
psql: FATAL:  Ident authentication failed for user "postgres"
hduser@master:/$ 

with postgres:

使用postgres

postgres@master:/opt/pentaho/biserver-ce$ psql -Upostgres -W analytics
Password for user postgres: 
psql (8.4.9)
Type "help" for help.

analytics=# 

How can I login to same database with a different user like hduseror some other?

如何使用不同的用户hduser或其他用户登录同一个数据库?

Thank you

谢谢

回答by A.H.

The default configuration of PostgreSQL allows "local" access to a database only to database users which have the same name as the OS user. "local" means without any IP traffic using only the Unix-Domain sockets. See the documentation for the configuration file pg_hba.confespecially the lines starting with "local" and the authentication method "peer" or "ident".

PostgreSQL 的默认配置只允许与操作系统用户同名的数据库用户“本地”访问数据库。“本地”意味着只使用 Unix 域套接字没有任何 IP 流量。请参阅配置文件的文档,pg_hba.conf尤其是以“local”开头的行和身份验证方法“peer”或“ident”。

On the other hand accessing postgres using an IP transport channels is by default configured to use passwords IF there IS a password. Therefore this should help youfor normal users.

另一方面,如果有密码,使用 IP 传输通道访问 postgres 默认配置为使用密码。因此,这应该对普通用户有所帮助。

foouser@host$ psql -U baruser -h 127.0.0.1 database

The bad message is, that the DB superuser postgresdoes NOT have a password by default, so you must set one first.

坏消息是,postgres默认情况下数据库超级用户没有密码,因此您必须先设置密码。

回答by limscoder

Postgres handles authentication and authorization separately.

Postgres 分别处理身份验证和授权。

Authentication options are configured in the file: pg_hba.conf -- this file describes what authentication methods users are allowed to use, and which hosts they can connect from.

身份验证选项在文件中配置: pg_hba.conf —— 该文件描述了允许用户使用哪些身份验证方法,以及他们可以从哪些主机连接。

Authorization to access databases and tables is configured by issuing GRANT statements in SQL.

访问数据库和表的授权是通过在 SQL 中发出 GRANT 语句来配置的。

On most Linux systems, the Postgres user is setup to use 'ident' authentication, and does not have a password by default, so if you wish to login using a password, you'll need to configure that with a SQL statement, and then alter your pg_hba.conf to allow the user postgres to login using a password:

在大多数 Linux 系统上,Postgres 用户设置为使用 'ident' 身份验证,并且默认情况下没有密码,因此如果您希望使用密码登录,则需要使用 SQL 语句进行配置,然后更改您的 pg_hba.conf 以允许用户 postgres 使用密码登录:

ALTER ROLE postgres WITH PASSWORD password

ALTER ROLE postgres WITH PASSWORD password

回答by digitaljoel

You could setup a .pgpassfile for hduser

你可以为 hduser设置一个.pgpass文件

回答by daydreamer

I added the following in pg_hba.confand it got fixed

我添加了以下内容pg_hba.conf并修复了

local   all         all                         trust