SSH between multiple Vagrant VMs

2

I am trying to install a local 3 node cluster of HP Vertica. The Vertica install uses SSH to install the DB Server software onto each node when triggered from any one of the nodes.

I get an error saying "Permission denied (public key). I have worked through the various StackOverflow posts and come up with a VagrantFile as follows:-

# -*- mode: ruby -*-
# vi: set ft=ruby :

BOX_IMAGE = "ubuntu/xenial64"
NODE_COUNT = 3

Vagrant.configure("2") do |config|
    (1..NODE_COUNT).each do|i|
      config.vm.define "vertica_node#{i}" do |subconfig|
        subconfig.vm.box = BOX_IMAGE
        subconfig.vm.hostname="verticaNode#{i}"

        if i == 1
          subconfig.vm.network "forwarded_port", guest: 5433, host: 5433, id: "Vertica DBEngine"
          subconfig.vm.network "forwarded_port", guest: 5450, host: 5450, id: "Vertica MC"
          subconfig.vm.network "forwarded_port", guest: 1527, host: 1527, id: "Vertica MCDatabase"
        end
        subconfig.vm.network "private_network", ip: "192.168.33.#{i + 10}"

        subconfig.vm.synced_folder "./data", "/vagrant/data", create: true

        subconfig.vm.provider "virtualbox" do |vb|
          vb.name = "VerticaUbuntu_Node#{i}"
          vb.memory = "2048"
        end

      end
    end
  config.ssh.forward_agent = true
  config.ssh.insert_key    = false
  config.ssh.private_key_path = ["~/.vagrant.d/insecure_private_key","~/.ssh/id_rsa"]
  config.vm.provision "shell", path: "bootstrap.sh"
  config.vm.provision "shell", privileged: false do |s|
    ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
    s.inline = <<-SHELL
    echo #{ssh_pub_key} >> /home/$USER/.ssh/authorized_keys
    sudo bash -c "echo #{ssh_pub_key} >> /root/.ssh/authorized_keys"
    SHELL
  end
end

All 3 VMs come up. I can SSH from the host to each guest. While on a guest I can ping the other guests.

If I try and SSH from a guest to one of the other guests I receive a message

The authenticity of host '192.168.33.11 (192.168.33.11)' can't be established.
ECDSA key fingerprint is SHA256:kEdfmMkISpmDMKGGOw77zCLakujVWZYRQomCMYTWZ0E.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.33.11' (ECDSA) to the list of known hosts.
Permission denied (publickey).

I should be grateful for any help in resolving this

Dave Poole

Posted 2018-04-09T07:26:47.820

Reputation: 121

Answers

1

I use Vagrant triggers to be able to ssh from one machine to another:

Vagrant.configure("2") do |config|
  config.vm.define "master", primary: true do |master|
    # something
  end

  config.vm.define "node" do |node|
    # something else
    node.trigger.after :up do |trigger|
      trigger.run = { inline: 
        "vagrant ssh master -- cp /vagrant/.vagrant/machines/node/virtualbox/private_key ~/.ssh/id_rsa"
      }
    end
  end
end

intelfx

Posted 2018-04-09T07:26:47.820

Reputation: 11