无法使用MD5方法从主机连接到在VM上运行的Postgres [英] Cannot connect to Postgres running on VM from host machine using MD5 method

查看:128
本文介绍了无法使用MD5方法从主机连接到在VM上运行的Postgres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个装有Vagrant的虚拟机,该虚拟机上运行有Postgres(端口5432),并转发到主机上的端口8280。

I have a VM set up with Vagrant that has Postgres running on it (on port 5432), forwarded to port 8280 on the host machine.

默认用户的密码,我可以在本地连接。

I have set the password for the default user and I can connect locally just fine.

我一直在尝试通过端口8280设置从主机的访问权限,但无法使其与 MD5作为信任方法一起使用。

I have been trying to set up access from the host machine over port 8280, and I have been unable to get it working with 'MD5' as the trust method.

我已设置 postgresql.conf 进行监听在所有地址上:

I have set up postgresql.conf to listen on all addresses:

# postgresql.conf
listen_addresses = '*'

我已经配置了 pg_hab.conf 如下:

# pg_hab.conf
#TYPE   DATABASE  USER  CIDR-ADDRESS  METHOD
host    all       all   0.0.0.0/0     md5

使用所有这些设置,如果我从主机上运行以下命令:

With all of these settings, if I run the following command from my host machine:

psql --host=127.0.0.1 --port=8280 --username=postgres -d mydb -c '\l'

提示输入密码,然后得到:

I am prompted for the password, and then I get:

psql: FATAL:  password authentication failed for user "postgres"

如果我随后将方法从 md5更改为信任,则无需输入密码,并且可以按预期进行连接。我的问题是-为什么我不能使用 md5进行连接?我知道我输入的密码是正确的(我已经更改了密码),但是由于某些原因它不起作用。

If I then change the METHOD from 'md5' to 'trust' I'm not asked for a password and I can connect as expected. My question is - why can't I connect using 'md5', which is what I want to be able to do? I know that the password I am entering is correct (I have changed it), but for some reason it isn't working.

推荐答案

<我有同样的问题。问题出在主机端,基本上防火墙阻止了我正在使用的端口。所以这就是我所做的(我正在使用OSX Mavericks)

I had the same exact problem. The issue was on the host side, basically the firewall was blocking the port I was using. So this is what I did (I am using OSX Mavericks)


  1. 打开端口(主机)

  1. Open the port (Host)

sudo ipfw添加7000 allow tcp from any to any dst-port 7001

修改Vagrantfile以允许进行端口转发

Modify Vagrantfile in order to allow portforwarding

config.vm.network forwarded_port,访客:5432,主机:7001

编辑postgresql.conf(来宾)

Edit postgresql.conf (Guest)

listen_addresses ='*'

编辑 pg_hba.conf (您可能想更好地调整它)

Edit pg_hba.conf (you might want to tune this better)

托管所有0.0.0.0/0 md5

现在,从主机正常使用端口(在我的情况下为7001)和 localhost作为主机地址进行连接

Now, from the host connect normally using the port (in my case 7001) and 'localhost' as host address

这篇关于无法使用MD5方法从主机连接到在VM上运行的Postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆