Skip to content

Instantly share code, notes, and snippets.

Forked from beddari/
Created June 3, 2012 19:13
Show Gist options
  • Save GUI/2864683 to your computer and use it in GitHub Desktop.
Save GUI/2864683 to your computer and use it in GitHub Desktop.
Allow Vagrant sudo-access without password for NFS-setup (for OS X)
# Script for placing sudoers.d files with syntax-checking
# Making a temporary file to contain the sudoers-changes to be pre-checked
TMP=$(mktemp -t vagrant_sudoers)
cat /etc/sudoers > $TMP
cat >> $TMP <<EOF
# Allow passwordless startup of Vagrant when using NFS.
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/su root -c echo '*' >> /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -e /*/ d -ibak /etc/exports
# Check if the changes we want are OK
visudo -c -f $TMP
if [ $? -eq 0 ]; then
echo "Adding vagrant commands to sudoers"
cat $TMP > /etc/sudoers
echo "sudoers syntax wasn't valid. Aborting!"
rm -f $TMP
Copy link

Mine was calling sed -E -e, so I had to add a -E.

Copy link

cabloo commented Apr 10, 2015

For those wondering, you can check exactly what commands your version of Vagrant is trying to run in /var/log/auth.log, at least on Ubuntu/Debian.

Copy link

chisleu commented Oct 22, 2015

In Mac OSX it is using a very long command with UUIDs for the sed command in the latest vagrant. I'm still working on getting it functional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment