Cannot connect to Postgres running on VM from host machine using MD5 method

泪湿孤枕 提交于 2019-12-02 18:31:19
Guillemo Mansilla

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. Open the port (Host)

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

  2. Modify Vagrantfile in order to allow portforwarding

    config.vm.network "forwarded_port", guest: 5432, host: 7001

  3. Edit postgresql.conf (Guest)

    listen_addresses = '*'

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

    host all all 0.0.0.0/0 md5

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

You need to set a password for the postgres user. It does not have one by default, so you cannot connect.

ALTER USER postgres PASSWORD 'somepassword';

Your local connections probably work because they're using unix sockets with peer authentication, not TCP/IP. If you use:

psql -h 127.0.0.1 -U postgres postgres

on the VM, you'll probably find that that fails too, because you're actually testing TCP/IP based connections now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!