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

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


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.