Vagrant passwordless ssh between boxes

Hello,
I'm trying to set up a passwordless ssh connection between two vagrant boxes.
From one machine i create ssh pair - upload the public key to the second box and when I try to ssh from VM1 to VM2 I get the error:
[email protected]: Permission denied (publickey).

Has anyone got suggestions on what do I do wrong?

3 thoughts on “Vagrant passwordless ssh between boxes”

  1. What are the IP address settings for the two vagrant boxes?

    What command are you using to initiate the SSH connection from box 1 to box 2?

    What configuration (if any) have you set up in `~/.ssh/config`?

    Reply
  2. I’m using following piece to share personal key among boxes, you can use an idea to propagate private key too:

    # vagrant provision –provision-with user_ssh
    config.vm.provision ‘user_ssh’, type: :shell, privileged: false do |s|
    ssh_pub_key = File.readlines(“#{Dir.home}/.ssh/id_rsa.pub”).first.strip
    s.inline = “echo #{ssh_pub_key} >> /home/$USER/.ssh/authorized_keys”
    end
    # vagrant provision –provision-with root_ssh
    config.vm.provision ‘root_ssh’, type: :shell, privileged: true do |s|
    ssh_pub_key = File.readlines(“#{Dir.home}/.ssh/id_rsa.pub”).first.strip
    s.inline = “mkdir -p /root/.ssh/; echo #{ssh_pub_key} >> /root/.ssh/authorized_keys”
    end

    Reply

Leave a Comment