I see a lot of people are getting this error but none apparently for the same reasons as me. An explanation for the reason in my case would be useful.
After adding this to my vagrant file:
config.vm.synced_folder "./home", "/home/vagrant"
I got the following error when using vagrant ssh
:
vagrant@127.0.0.1: Permission denied (publickey)
When I removed the synced_folder line the error no longer shows and vagrant ssh
works fine.
What's happening and why can't I do this?
When you configure the guest to have a synced folder at /home/vagrant
, it overwrites the entire folder with the contents of your synced folder. Vagrant places its key in the ~/.ssh/authorized_keys
file, which allows it to ssh into the guest.
My personal set-up is as follows:
config.vm.synced_folder "./code", "/home/vagrant/code"
This way you create a new directory in your root directory without overwriting the ssh keys file.
Hope this helps, best regards.