Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant synced folder using NFS wrong permissions

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?

like image 215
Justin Avatar asked Jan 20 '16 01:01

Justin


1 Answers

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.

like image 189
Felipe Zavan Avatar answered Sep 28 '22 11:09

Felipe Zavan