Vagrant synced folder using NFS wrong permissions
Asked Answered
S

2

10

Trying to use the NFS plugin with a synced folder in Vagrant, and it is working, except that in the guest (VM) the permissions are wrong:

-rw-r--r-- 1  501 dialout    0 Jan 20 00:51 a
-rw-r--r-- 1  501 dialout    0 Jan 20 00:51 foo

I tried setting up the uid and gid according to the Vagrant documentation in the Vagrantfile:

config.nfs.map_uid = 1001
config.nfs.map_gid = 1001

Which I was hoping would use the correct user/group in the guest, but it is still using 501 and dialout.

Any ideas?

Sarette answered 20/1, 2016 at 1:0 Comment(4)
Which specific plugin are you using? I see several NFS-related Vagrant plugins available. Also, you can set the user and group permissions on a synced folder in Vagrant without needing a plugin: vagrantup.com/docs/synced-folders/basic_usage.htmlMalvia
can you add something like :mount_options => ["dmode=777", "fmode=666"] in your sync_folder configuration ?Soapberry
what is your OS host for Vagrant ?Meurer
Host is OS X. Using the default built in NFS support baked into Vagrant.Sarette
J
2

This worked for me on a MacOS Catalina host and Ubuntu 18.04 guest (Vagrant 2.2.9, VirtualBox 6.1.12):

opts = {
  type: 'nfs',
  linux__nfs_options: ['no_root_squash'],
  map_uid: 0,
  map_gid: 0
}

config.vm.synced_folder '.', '/var/www/project', opts

You can then chown and chmod as usual:

$ sudo chown -R vagrant:vagrant /var/www/project
$ sudo chmod -R 774 /var/www/project/logs

ATTENTION: no_root_squash is fine for development environments, but DON'T use it for production. It allows remote root users to change any file in the shared file system.

Another option might be to use the vagrant-bindfs plugin. But I didn't feel like installing and configuring an extra plugin for this.

Jackstraw answered 20/7, 2020 at 14:25 Comment(1)
For Ubuntu host and Ubuntu guest I get it works without linux__nfs_options: opts = {type: 'nfs', map_uid: 0, map_gid: 0}Arsis
C
-4

I had the same issue. It started after I've upgraded my MacOS to mcOS Sierra version 10.12.1. The trick that worked for me was to set/force the owner and group to the 'vagrant' user in Vagrantfile like this:

    config.vm.synced_folder "/users/myuser/src/", "/home/vagrant/src/", owner: "vagrant", group: "vagrant"

I also had to remove the 'nfs: true' setting that was previously there in the Vagrantfile.

Cephalonia answered 13/11, 2016 at 14:38 Comment(1)
This is not a solution, it's simply turning off NFS instead of fixing the problem :-(Putout

© 2022 - 2024 — McMap. All rights reserved.