20

I've been playing around with setting up an environment using Vagrant, and I'm having an issue with the vagrant ssh command.

When I change the path of the mounted share folder in the Vagrantfile, and do a vagrant reload, I'm no longer able to vagrant ssh without it asking me for a password.

This was my original configuration for a mounted share, which works:

config.vm.synced_folder "./", "/home/vagrant/shared"

This is what I was trying to change to and it doesn't work after vagrant reload (asks me for password):

config.vm.synced_folder "./", "/home/vagrant"

Everything else in the file remained unchanged. Any idea what's going on here?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Tommy
  • 203
  • 1
  • 2
  • 5
  • 1
    the vagrant folder automatically share with the guest mc, so you don't need write some thing to share it. if the ssh command need a password, you can try with 'vagrant', almost box use this words as default password for ssh – Makio May 12 '14 at 11:03
  • Thanks for response. I tried vagrant password before and didn't work. I commented out that synced folder line and did vagrant destroy then vagrant up. I can vagrant ssh in no problem but I'm not seeing any files in /home/vagrant now, weird. – Tommy May 12 '14 at 14:02
  • not /home/vagrant, the default synced folder is /vagrant, not in home folder, please try it – Makio May 13 '14 at 01:30
  • Oh you're right. I see the files in /vagrant now. Looked at the docs and they do say the default shared is /vagrant, should have read more carefully. Thanks for your help ! – Tommy May 13 '14 at 05:32
  • Just want to add the following to this. One of the failures and prompt for password I discovered was where you put the vagrant line in sudoers. make sure it is after "wheel" – cuky Jun 15 '15 at 23:12

1 Answers1

34

Take note of what is actually happening here. When you share the /home/vagrant folder the VM Provider (most likely VirtualBox) has control of that folder and the permissions get all mangled by VirtualBox. You won't be able to set the 0700 perms for the .ssh folder nor will you be able to set the 0600 perms for the authorized_keys file inside the .ssh folder. Consequently, the vagrant ssh command will explicitly ask you for the password since it can't check the public key in the .ssh folder.

Makio was right about /vagrant being the default share folder. You can share pretty much any folder you want except for the /home/vagrant folder. I know about this personally because I ran into the very same issue you did. By allowing Vagrant to control the /home/vagrant folder, the permissions get set appropriately for vagrant ssh to function properly.

Glad it's resolved and I hope I shed a bit more light on exactly why this gives people a problem.

c0p

Jeff
  • 6,643
  • 3
  • 25
  • 35
cOp
  • 629
  • 6
  • 7
  • Ah that makes sense. Thanks for answering. Perhaps if I had set the appropriate permissions on /home/vagrant via mount options it would have worked? Ie owner vagrant and appropriate permissions for fmode and dmode? http://serverfault.com/questions/398414/vagrant-set-default-share-permissions I think ultimately it's best to leave /home/vagrant alone though. – Tommy May 21 '14 at 06:48
  • That would not have worked for you. I tried that myself before finding out what VirtualBox does with shared folder permissions. Believe me. I tried it already. I am happy to see that this explained to you why this is an issue. I was stumped for a while before I understood what I was actually doing. Wanna hit me up with the 'answer' points? Awesome! c0p – cOp May 21 '14 at 06:54
  • Yeah, I know what you mean. I added what I did for others to understand why **not** to share that **/home/vagrant** folder. I was stumped for a while before I figured it out. But now, everyone will know. – cOp May 21 '14 at 07:08
  • Fantastic answer, thank you for writing this - and explaining it. – Rcynic Jan 12 '16 at 21:25