Vagrant: Mounting nfs requires sudo, but the sudoers file given in documentation no longer works.

Created on 22 Jul 2015  路  13Comments  路  Source: hashicorp/vagrant

After upgrading to Vagrant 1.7.4, the following sudoers file, given in the documentation, no longer produces the desired result on Ubuntu 14.04:

Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /etc/init.d/nfs-kernel-server status
Cmnd_Alias VAGRANT_NFSD_START = /etc/init.d/nfs-kernel-server start
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /etc/exports
%sudo ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY, VAGRANT_EXPORTS_REMOVE

Running vagrant up --debug, unfortunately, results in no hints on what command it actually wants to run, so I find it quite difficult to figure out what do I need to do to make it work again.

It worked in 1.7.2.

bug documentation

Most helpful comment

The commands given in the documentation still do not work for me on OS X. They used to, but they stopped working (i.e. now require a password again) somewhere around 1.7.x...

All 13 comments

Confirmed on 14.10, looking at /var/log/auth.log I don't see the failing command either

Iv tracked this to a series of commits done on nfs.rb while solving this issue, it seems that the exports remove has changed and new cp command added.

Still I'm unable to produce a working sudoers entry to fix this

I think that iv managed to find a working solution:

只Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_EXPORTS_COPY = /bin/cp /tmp/exports /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /etc/init.d/nfs-kernel-server status
Cmnd_Alias VAGRANT_NFSD_START = /etc/init.d/nfs-kernel-server start
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /tmp/exports
%sudo ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY, VAGRANT_EXPORTS_REMOVE, VAGRANT_EXPORTS_COPY

Iv added a copy and changed the sed remote command

Confirmed, it works. Thanks for figuring this one out.

I've tried this in 1.7.4 on Ubuntu 15.04 and sadly it doesn't work :(

the sed line should not need sudo privileges, as it is writing to a temp file.

Thanks for your fix @narkisr, confirmed working with vagrant 1.7.4 and Ubuntu 14.04.02

@narkisr Works for me too on Debian (Stretch).

Weird, but @narkisr solution does not work for me on Ubuntu 14.04 LTS.

Woohoo! Thanks @sethvargo!

The commands given in the documentation still do not work for me on OS X. They used to, but they stopped working (i.e. now require a password again) somewhere around 1.7.x...

Not working for me on debian jessie

For future googlers:
Se the section ROOT PRIVILEGE REQUIREMENT in the docs: https://www.vagrantup.com/docs/synced-folders/nfs.html

Managed to solve this on my mac by adding proper lines to my /etc/sudoers file.

Was this page helpful?
0 / 5 - 0 ratings