【问题标题】:Could not connect to database postgres pg_hba (OSX)无法连接到数据库 postgres pg_hba (OSX)
【发布时间】:2015-05-08 10:26:05
【问题描述】:

所以我正在尝试设置 PostgreSQL 以在我的 Mac 10.9 Mavericks 机器上与 metasploit 一起使用。我正在尝试按照此页面上概述的说明进行操作。 http://www.darkoperator.com/installing-metasploit-framewor/ 我得到了命令:

createuser msf -P -h localhost

结果如下:

$ createuser msf -P -h localhost
Enter password for new role: 
Enter it again: 
createuser: could not connect to database postgres: FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "myname", database "postgres", SSL off

我把写着“我的名字”的部分改成了那个,因为我不想在这里张贴我的名字。我已经在互联网上搜索了几天的解决方案,我很确定我需要编辑 pg_hba.conf。这是我的 pg_hba.conf 文件的内容:

 80 # TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
 81 
 82 # "local" is for Unix domain socket connections only
 83 #local   all         all                               trust
 84 host     all         all        0.0.0.0/0             md5
 85 local   all         all                               md5
 86 # IPv4 local connections:
 87 host    all         all         127.0.0.1/32          md5
 88 # IPv6 local connections:
 89 host    all         all         ::1/128               md5
 90 
 91 # TYPE  DATABASE        USER            ADDRESS                 METHOD
 92 #local   postgres        postgres                                trust
 93 #local   msf_db          msf_user                                trust
 94 # Allow replication connections from localhost, by a user with the
 95 # replication privilege.
 96 #local   replication     postgres                                trust
 97 #host    replication     postgres        127.0.0.1/32            trust
 98 #host    replication     postgres        ::1/128                 trust

你能告诉我我需要从这部分添加/删除(注释掉)什么来启动和运行 postgresql 吗?

如果您需要更多信息来帮助我了解如何解决此问题,请告诉我。谢谢!!

编辑 1:

我被告知我需要做的就是重新启动数据库,这就是我得到的:

sh-3.2# pg_ctl stop -D /opt/local/var/db/postgresql93/defaultdb
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.

我以 su 身份登录以完成此操作...

编辑 2:

然后我尝试使用我的默认用户完成此操作,这就是我得到的(我确定我为自己输入了正确的密码)

sxxx:~ sxxx$ createuser msf -P -h localhost
Enter password for new role: 
Enter it again: 
Password: 
createuser: could not connect to database postgres: FATAL:  password authentication failed for user "sxxx"

编辑 3:

感谢其他人的帮助,我发现我需要登录我的 postgres 用户来创建它。我仍然无法完成这就是我所做的:

Sxxx-MacBook-Pro:~ sxxx$ sudo su - postgres
Sxxx-MacBook-Pro:~ postgres$ createuser msf -P -h localhost
Enter password for new role: 
Enter it again: 
createuser: could not connect to database postgres: FATAL:  role "postgres" does not exist

这对我来说很奇怪。

编辑 4:

我奇迹般地关闭了终端窗口并打开了一个新窗口,而我一直在做的同样的事情奏效了:

Sxxx-MacBook-Pro:~ sxxx$ createuser msf -P -h localhost
Enter password for new role: 
Enter it again: 
Sxxx-MacBook-Pro:~ sxxx$ createdb -O msf msf -h localhost
Sxxx-MacBook-Pro:~ sxxx$ 

【问题讨论】:

  • pg_hba.conf 的第一个非注释行已经允许来自任何 IPv4 地址的任何连接,所以你只需要让 postgresql 重新加载该文件。
  • @DanielVérité 如何让 PostgreSQL 重新加载该文件?
  • 基本上使用pg_ctl reload,但具体取决于您使用的 postgres 包。如果您只是重新启动 postgres,这也将起作用。
  • @DanielVérité 当我尝试关闭数据库时出现错误。以及当我尝试重新启动它时:查看我的编辑:
  • 请阅读您安装在基本东西上的 postgres 包中的说明。 Several packages exist 当涉及到什么用户运行命令以及他们所在的目录时,他们每个人都有自己的程序。

标签: sql database postgresql metasploit createuser


【解决方案1】:

检查 PostgreSQL 以什么用户身份运行。通常这将是pgsqlpostgres。以该用户身份运行createuser 命令。

$ sudo su
# su postgres -c 'createuser msf -P -h localhost'

您可能不需要触摸pg_hba.conf 文件。

【讨论】:

  • 通常这将是 pgsql 或 postgres:在 MacOS 中并不常见。用于 homebrew 的 postgres.app 或 IIRC postgres 等软件包在桌面用户下运行。
  • 你是对的。出于某种原因,我的笔记本电脑上有一个 postgres 用户,但自制配方确实以桌面用户身份运行它。换句话说:如果他以自己而不是 root 身份运行createuser,那么原始发布者的问题应该会消失。
  • 除非使用由 entreprisedb 打包的 postgres 或实际使用 postgres 用户的其他工具之一。
  • 嘿@DanielVérité 我添加了一个新的编辑。我认为我们离解决这个问题越来越近了!
  • 嘿@PhilipPaeps 我认为我们正在接近解决这个问题。我添加了我得到的内容的编辑。
猜你喜欢
  • 2017-11-12
  • 1970-01-01
  • 2016-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-14
  • 2019-12-14
  • 1970-01-01
相关资源
最近更新 更多