我正在使用基于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。 - 我创建的角色与服务器找到的身份不匹配。
在第一种情况下,您能判断语法是否正确吗?我试图添加&#34; sameuser&#34;在身份之后,但它破坏了我的pg_hba,并且map = sameuser,但是我得到了与提到的相同的错误。
在第二种情况下,我在每个会话上使用批处理运行来获取用户名,如
find /c "%username%"
或Python3.6函数os.getlogin(),它产生相同的结果。
PostgreSQL如何获得其#34; ident&#34; ?更重要的是,我如何重现这个过程以了解PostgreSQL会识别的会话的意见?
感谢。
答案 0 :(得分:1)
阅读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.
希望有所帮助