2017-07-11 41 views
1

我正在使用基于Windows的本地网络,并且我想使用网络的帐户系统来允许用户连接到我的数据库。PostgreSQL 9.5在pg_hba中使用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,但是我得到了与提到的相同的错误。

在第二种情况下,我使用的每一个会话的批处理来得到这样

find /c "%username%" 

或Python3.6功能os.getlogin(),它产生相同的结果的用户名。

PostgreSQL如何获得其“ident”?更重要的是,我如何重现这个过程来了解PostgreSQL将会识别的会话的理念?

谢谢。

回答

1

阅读ident.conf manual,并使用从hba_file manual的例子后,我设置了:

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

现在,我从同一台计算机连接到其外部IP:

[email protected]:~$ 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" 

似乎很熟悉。虽然我遵循手册。最后一件事要检查:

[email protected]:~$ telnet localhost 113 
Trying 127.0.0.1... 
telnet: Unable to connect to remote host: Connection refused 

所以没有提供我的身份。诚如here

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

所以现在尝试:

[email protected]:~$ 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. 

希望它可以帮助

+0

谢谢您的广泛的答案。不幸的是,如果我通过代码中“sudo”的存在正确理解,这将适用于Linux环境。在我的情况下,我工作在一个完整的Windows,所以它似乎我不能使用你的答案......(我偶然在我的搜索中看到,也许ident协议可能不适用于Windows ...) –

+0

https :?//www.google.lt/search espv = 2&q =的Windows +订货号+服务器和OQ =的Windows +订货号+服务器和gs_l = serp.3..0j0i22i30k1l3.787.787.0.1678.1.1.0.0.0.0.98.98.1.1.0。 ... 0 ... 1.1.64.serp..0.1.97.beVICgkCXkw其中一些在谷歌搜索 –