in Developer Experience

Fast and painless NFS for your Vagrant environment

If you are using NFS with Vagrant you are probably tired of password prompts. But a few modifications to /etc/sudoers file can help you!

To edit /etc/sudoers file always use visudo. This way you won’t save the file with errors and you don’t damage your system.

$ sudo visudo

And input the following for Fedora:

# Allow Vagrant to manage /etc/exports
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /usr/bin/systemctl status nfs-server.service
Cmnd_Alias VAGRANT_NFSD_START = /usr/bin/systemctl start nfs-server.service
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /etc/exports

How does that work? Vagrant runs the above mentioned commands to edit the /etc/exports file so we just let it to do so without asking for root permissions. To know the right commands you need to scan the Vagrant source code, but there is also a /contrib folder in the Vagrant repository that tries to gather information such as this one (the above snipped is taken from there). Note that this snipped allows the password-less NFS for vagrant group. You can change the group to the one you like or add yourself to this group with sudo usermod -a -G vagrant USERNAME.

If you still need to set up NFS, read my previous post on setting NFS on Fedora.

Write a Comment