Vagrant provision shell : can not run ssh-copy-id

0 votes

I have a sinple Vagrant file, which create 3 instances :

config.vm.define "node1" do |subconfig|
    subconfig.vm.box = "ubuntu/trusty64"
subconfig.vm.network "private_network", ip: "192.168.33.10"
end

config.vm.define "node2" do |subconfig|
    subconfig.vm.box = "ubuntu/trusty64"
subconfig.vm.network "private_network", ip: "192.168.33.11"
end

 config.vm.define "master" do |subconfig|
     subconfig.vm.box = "ubuntu/trusty64"
subconfig.vm.network "private_network", ip: "192.168.33.9"
subconfig.vm.provision :shell, path: "install.sh"
end

On master node, i want to generate ssh-key , then copy it to 2 other nodes. My provision shell ( install.sh ) :

apt-get install sshpass -y
ssh-keygen -t rsa -b 4096 -C "tuananh93nguyen@gmail.com" -N "" -f /home/vagrant/.ssh/id_rsa
sudo chmod -R 755 /home/vagrant/.ssh
sshpass -p vagrant ssh-copy-id -o StrictHostKeyChecking=no vagrant@192.168.33.10
sshpass -p vagrant ssh-copy-id -o StrictHostKeyChecking=no vagrant@192.168.33.11

But i got this error when running 2 last line :

> master: /usr/bin/ssh-copy-id: ERROR: No identities found

But if i ssh into master node, then run install.sh again, everything is fine . I think it may be about user permission when run on vagrant. How can i fix it ?

Jun 16, 2018 in DevOps Tools by Atul
• 10,240 points
245 views

1 answer to this question.

0 votes

I think I can help you with this issue.

You have an issue that you're running your script with root user but pushed in vagrant folder, so you're confused.

Add privileged: false in your Vagrantfile script:

subconfig.vm.provision :shell, path: "install.sh", privileged: false

so it will be run with vagrant user rather than root and you do not need then to change the permission of the key (remove sudo chmod -R 755 /home/vagrant/.ssh)

small note: if you're using the same box for all 3 machines, you can just have a common variable and remove all lines of subconfig.vm.box = "ubuntu/trusty64":

config.vm.box = "ubuntu/trusty64"

config.vm.define "node1" do |subconfig|
    subconfig.vm.network "private_network", ip: "192.168.33.10" 
end
answered Jun 16, 2018 by shubham
• 6,890 points

edited Jun 16, 2018 by shubham

Related Questions In DevOps Tools

+4 votes
2 answers

Jenkins not showing Maven Release Plugin

Make your project type Maven Project. This ...READ MORE

answered Oct 11, 2018 in DevOps Tools by Hannah
• 16,570 points
858 views
0 votes
1 answer
0 votes
1 answer

Gunicorn stuck on docker when run is executed with flask application

Here's something that you could try: Check your ...READ MORE

answered Jun 13, 2018 in DevOps Tools by ajs3033
• 7,280 points
793 views
0 votes
1 answer

dpkg a deb file in a local fodler on vagrant

Copy the file in the vagrant folder ...READ MORE

answered Jun 14, 2018 in DevOps Tools by DareDev
• 6,810 points
52 views
0 votes
2 answers
0 votes
2 answers
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
215 views
0 votes
3 answers