通过SSH进行Postgres远程访问,要求输入数据库密码

时间:2018-09-02 03:30:22

标签: postgresql ubuntu ssh pgadmin datagrip

在Ubuntu 18.04沙箱上安装的Postgres 10

如果我使用Putty SSH连接到我的机器,我就可以连接到数据库。 (在VirtualBox中已提供localhost端口22转发)

dangel@ubuntu1804nginx:~$ psql
psql (10.5 (Ubuntu 10.5-0ubuntu0.18.04))
Type "help" for help.

dangel=#

但是,当尝试通过PGAdmin或DataGrip设置远程连接时,系统会要求我输入数据库用户名和密码...

enter image description here

enter image description here

The specified database user/password combination is rejected: 
[08004] The server requested password-based authentication, but no password was provided

我尝试将databaseuser字段留空,并填充它们。一样。

这让我感到困惑的原因是,我认为通过SSH连接应该使用ident身份验证吗?从而不需要密码? (我没有设置密码)(我知道我必须缺少一个简单的概念,但这是什么?)

编辑: 日志文件条目

2018-09-02 03:57:07.865 UTC [13127] dangel@dangel FATAL:  password authentication failed for user "dangel"
2018-09-02 03:57:07.865 UTC [13127] dangel@dangel DETAIL:  User "dangel" has no password assigned.
        Connection matched pg_hba.conf line 94: "host    all             all             ::1/128                 md5"

1 个答案:

答案 0 :(得分:0)

您的pg_hba要求使用该密码,但是用户没有密码,因此无法满足要求。

在数据库中为数据库用户分配密码(alter user dangel password 'open_sesame';或使用\password psql命令),或将“ pg_hba.conf”的第94行更改为“信任”而不是“ md5” ”。或第三个选项(未试用),使“常规”选项卡上的“主机”为空字符串,而不是“ localhost”。

您的psql命令有效,因为它使用的是pg_hba中的“本地”条目,而不是“主机”条目。如果要使用psql进行调试,则需要使用psql -h localhost,这将迫使它像其他命令一样通过相同的pg_hba条目。

相关问题