Vagrant Up and annoying NFS password asking


Solution 1

The official Vagrant docs now cover this:

You need to add entries to the /etc/sudoers file, and the way to edit that is to type this at the terminal: sudo visudo

Type your password, and you're editing the file. You'll want to paste these lines below (depending on whether you are running Vagrant on OS X or Linux.

If you're not familiar with vim, which it opens in, this page helped. Basically, copy the appropriate block of text below. Then, in visudo, go to the spot you want to paste text into the file (the end of the file is fine), and hit "i" to go into insert mode. CMD+V to paste your text. Then, hit ESC, then type :w to save your changes and then :q to quit.

As of version 1.7.3, the sudoers file in OS X should have these entries:

Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports

And Linux should have these entries:

Cmnd_Alias VAGRANT_EXPORTS_CHOWN = /bin/chown 0\:0 /tmp/*
Cmnd_Alias VAGRANT_EXPORTS_MV = /bin/mv -f /tmp/* /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

Note that these change from one version of Vagrant to another, so the above might be outdated. The important thing is that the docs now cover it.

Solution 2

For anyone doing this for OSX (I'm on MacOS Sierra Version 10.12.6) I had a hard time with permissions even after adding those lines. This post really helped:

Basicly its the fact that you dont have permissions set for the that folder yourself. So you need to run:

sudo chmod +a "$USER allow write,append" /etc/hosts

Solution 3

The exact commands can change between Vagrant versions, so it's impossible to list ones that would always work.

Anyway, the sudoers rules in this gist should be still quite close. Check out /var/log/auth.log if it reveals the actual commands for your Vagrant version and adapt the rules accordingly.

Solution 4

adding , nfs_export: false at the end of the config.vm.synced_folder-lines in the Vagrantfile, solved it for me.

If you already have a working nfs-config, and don't need your Vagrant to overwrite it each time you start, then you can just disable the writing to the export-file.

This also solves the collision problem, if you have more then one Vagrant trying to access the same folder, as for example have 2 almost identical Vagrants, one running php 5.6 and one running php 7.2.


Related videos on Youtube

Timur Fayzrakhmanov
Author by

Timur Fayzrakhmanov

Updated on September 18, 2022


  • Timur Fayzrakhmanov
    Timur Fayzrakhmanov 10 months

    Sorry for the language mistakes I've made. I'm trying to prevent vagrant asking the password when it mounts shared folders by NFS:

     [server] Exporting NFS shared folders...
     Preparing to edit /etc/exports. Administrator privileges will be required...
     [sudo] password for timur: #!!!

    I've red many online resources like github and other author's posts, but nothing work for me...

    I tried the instructions was found here. I don't have deep cli working knowledge. So could anybody give correct solution for my problem?

    • Taytay
      Taytay over 6 years
      Could I kindly request to have the accepted answer now that this has been covered in the Vagrant docs?
    • gam6itko
      gam6itko over 4 years
      First of all you need to check Is service nfs-server installed on your machine.
  • Timur Fayzrakhmanov
    Timur Fayzrakhmanov over 9 years
    Thanks, but I tried this solution a long ago - it is doesn't work for me.
  • Tgr
    Tgr almost 7 years
    Weirdly this is not working for me, even though /var/log/auth.log only contains commands which are listed there and I can manually verify that the sudo permissions are working.
  • Emil Vikström
    Emil Vikström almost 6 years
    Instead of editting the main sudoers file I recommend adding this as a new file in /etc/sudoers.d to avoid future conflicts when updating the OS. On Ubuntu: sudo visudo -f /etc/sudoers.d/vagrant-nfs or OSX: sudo visudo -f /private/etc/sudoers.d/vagrant-nfs
  • Petr Cibulka
    Petr Cibulka over 5 years
    This helped, thank you! Just a quick comment to your advice to get around vim editor: Just open visudo with sudo EDITOR=nano visudo command, which allows you to bypass vim completely.
  • Luis Milanese
    Luis Milanese over 4 years
    Gotta love "TL&DR" people! Cheers.
  • FlyingV
    FlyingV over 4 years
    Thanks! Don't forget to upvote ;)
  • Luis Milanese
    Luis Milanese over 4 years
    Because of your "TL&DR" you deserve all the upvotes one can get, but truth is your answer didn't help me. Not because it's not good, but the problem I was having was slightly different from what was asked in the first place. Still, thank you for you good attitude. :)