No password required for vagrant operations on mac

By Selwyn Polit, 25 August, 2021

I have to often issue commands like: vagrant up, or vagrant reload and OSX wants to be sure that I know what I am doing so it cleverly asks for my password.  Thanks to the efforts of a very smart coworker, there is a workaround to this problem.


First do:
which sed

and replace the /usr/bin/sed below with your path to sed)

These go under cmd alias specification section

Use this command to edit /etc/sudoers (don't do it directly):
sudo visudo

# Allow passwordless startup of Vagrant with vagrant-hostsupdater.
Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts
Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/bin/sed -i -e /*/ d /etc/hosts

# Allow passwordless startup of Vagrant with NFS synced folder option.
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

This goes toward the end of the file after this code:

# root and users in group wheel can run anything on any machine as any user
root            ALL = (ALL) ALL
%admin          ALL = (ALL) ALL

Add this:


Voila!  Now you can issue commands like:

vagrant up

and they will merrily be executed by OSX without requiring a password.  Thanks to Scott Reese of Acquia for sharing this with me.