无法连接到数据库postgres pg_hba(OSX)

时间:2015-03-06 18:23:06

标签: sql database postgresql metasploit createuser

所以我试图在我的Mac 10.9 Mavericks机器上设置PostgreSQL以与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

我更改了说" myname"因为我不想在这里张贴我的名字。我已经在互联网上搜索了几天来解决这个问题,我很确定我需要编辑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$ 

1 个答案:

答案 0 :(得分:0)

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

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

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