gpt4 book ai didi

PostgreSQL 9.5 在 pg_hba 中使用 ident

转载 作者:行者123 更新时间:2023-11-29 13:18:58 25 4
gpt4 key购买 nike

我在基于 Windows 的本地网络上工作,我想使用网络的帐户系统来允许用户连接到我的数据库。

据我所知,正确的方法是在“ident”上设置 pg_hba 方法:

host    all    all    10.0.0.0/8      ident

但是当我这样做时,我收到一条消息说

"Error connecting to the server: FATAL: ident authentication failed for user <user>"

据我所知,我的猜测是可能存在两个问题:- 我没有正确设置 pg_hba。- 我创建的角色与服务器找到的身份不匹配。

在第一种情况下,你能判断语法是否正确吗?我试图在 ident 之后添加“sameuser”,但它损坏了我的 pg_hba,还有 map=sameuser,但我得到了与提到的相同的错误。

在第二种情况下,我在每个 session 上使用批处理来获取用户名,如

find /c "%username%"

或 Python3.6 函数 os.getlogin(),产生相同的结果。

PostgreSQL 如何获得它的“身份”?更重要的是,我如何重现此过程以了解 PostgreSQL 将识别的 session 标识?

谢谢。

最佳答案

看完ident.conf manual并使用 hba_file manual 中的示例,我这样设置:

postgres=# create user ident_user_db;
CREATE ROLE
vao@vao-X102BA:~$ sudo tail -n 1 /etc/postgresql/9.6/main/pg_hba.conf
host all all 192.168.8.0/24 ident map=vao_ident
vao@vao-X102BA:~$ sudo tail -n 1 /etc/postgresql/9.6/main/pg_ident.conf
vao_ident vao ident_user_db

现在我从同一台机器连接到它的外部 IP:

vao@vao-X102BA:~$ psql -h 192.168.8.107 -U ident_user_db
psql: FATAL:  Ident authentication failed for user "ident_user_db"
FATAL: Ident authentication failed for user "ident_user_db"

似曾相识。虽然我遵循手册。最后要检查的事情:

vao@vao-X102BA:~$ telnet localhost 113
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

所以没有什么能提供我的身份。根据建议here

vao@vao-X102BA:~$ sudo apt-get install oidentd
...
vao@vao-X102BA:~$ telnet localhost 113
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
telnet> quit
Connection closed.

所以现在试试:

vao@vao-X102BA:~$ psql -h 192.168.8.107 -U ident_user_db -d vao
psql (9.6.3)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

希望对你有帮助

关于PostgreSQL 9.5 在 pg_hba 中使用 ident,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45033058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com