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 17, 2018 in DevOps Tools by Atul
• 10,240 points
1,351 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 17, 2018 by shubham
• 7,340 points

edited Jun 17, 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
• 18,520 points
5,069 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 14, 2018 in DevOps Tools by ajs3033
• 7,300 points
6,713 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,890 points
666 views
0 votes
2 answers
0 votes
2 answers
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,035 views
0 votes
3 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP