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,200 points
152 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,480 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
• 14,080 points
470 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,000 points
324 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,520 points
33 views
0 votes
2 answers
0 votes
1 answer
+13 votes
2 answers
0 votes
3 answers

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.