Vagrantfile w/ multiple hosts | SSH FROM VM to VM

i got following config:

config.vm.define "webserver" do |webserver|

...

webserver.vm.hostname = "webserver"

[webserver.vm.network](https://webserver.vm.network) :private\_network, ip: "[192.168.6.65](https://192.168.6.65)"

...

config.vm.define "database" do |database|

...

database.vm.hostname = "database"

[database.vm.network](https://database.vm.network) :private\_network, ip: "[192.168.6.66](https://192.168.6.66)"

....

the vms come up, I can access them via vagrant ssh, the vms can ping each other but what dosen' work is to establish an SSH session from one host to another. i tried a thousand ways/trys to exchange public keys (autorized\_keys file).. but all i get (always) is:

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '[192.168.6.66](https://192.168.6.66)' (ECDSA) to the list of known hosts.

vagrant[@192.168.6.66](mailto:[email protected])'s password:

Permission denied, please try again.

3 thoughts on “Vagrantfile w/ multiple hosts | SSH FROM VM to VM”

  1. Make sure that you use the correct file `~/.ssh/authorized_keys` (with an “h” after the “t”). Also make sure that `~/.ssh/authorized_keys`, `~/.ssh` and `~` itsself are only writeable by the user (not the group and not others).

    Reply
  2. I’ve only tried the CentOS boxes so far but Vagrant boxes seem to have “PasswordAuthentication” set to no in /etc/ssh/sshd\_config which means you need to use keys, if you want to be able to use passwords change it to yes and restart sshd.

    The next issue could be your key permissions, check they are correct:

    $ stat -c ‘%a %n’ ~/.ssh
    700 .ssh
    $ stat -c ‘%a %n’ ~/.ssh/*
    644 .ssh/authorized_keys
    600 .ssh/id_rsa
    644 .ssh/id_rsa.pub
    644 .ssh/known_hosts

    If the VM’s are CentOS/RHEL/Fedora it could also be selinux causing problems or more to the point incorrect context on the files causing problems, you can restore the context of \~/.ssh using restorecon:

    restorecon -R -v ~/.ssh

    Reply

Leave a Comment