Enable ssh [email protected] from Vagrantfile

I want to have a Vagrant-File that creates a simple VM for Ansible-Testing. For this I need a machine that I can ssh into as root and from everywhere. I want it to have an static IP so I can have unchanged SSH-Host settings and the VM should be in a private Network, obviously it should run python2.7 - So far so good.

I can get everything running EXCEPT dynamically copy my public SSH key into the VMs root authorized\_keys file on creation via the Vagrantfile.

I tried everything I found online but nothing seems to work. This is my latest attempt:

`id_rsa_pub =` [`File.read`](https://File.read)`("~/.ssh/id_rsa.pub") #localtion of your pub key`

`config.vm.provision "shell", inline: <<-SHELL` `sudo -i` `echo "echo "#{id_rsa_pub}" >> /root/.ssh/authorized_keys`


There must be an obvious way to do such an basic task, right?

2 thoughts on “Enable ssh [email protected] from Vagrantfile”

Leave a Comment