1

I'm getting into Vagrant and I installed a plugin that update my Mac's /etc/hosts to add a domain and map the IP address to the domain. The only problem that in order to change the file, it needs admin access.

Is it safe to set the permissions of /etc/hosts to 664, where the owner and group has read and write access and everyone else can read?

Or should I use 644 where the owner has read and write and everyone else has read access?

Thanks,

1

Is it safe to set the permissions of /etc/hosts to 664, where the owner and group has read and write access and everyone else can read?

It depends on how well you maintain the system. Basically it shouldn't be a problem, especially as you are free to change the file group-membership to a single-user-group for your account only (if there were processes reading the file using default 4 permission for group, they would access now using the same permission for others).

Nevertheless, if you use Vagrant Hostmanager plugin, there are clear instructions how to remove the necessity to provide password at run-time, by adding some configuration to sudoers file:

Add the following snippet to the sudoers file (e.g. /etc/sudoers.d/vagrant_hostmanager):

Cmnd_Alias VAGRANT_HOSTMANAGER_UPDATE = /bin/cp <home-directory>/.vagrant.d/tmp/hosts.local /etc/hosts
%<admin-group> ALL=(root) NOPASSWD: VAGRANT_HOSTMANAGER_UPDATE

Replace <home-directory> with your actual home directory (e.g. /home/joe) and <admin-group> with the group that is used by the system for sudo access (usually sudo on Debian/Ubuntu systems and wheel on Fedora/Red Hat systems).

If necessary, add yourself to the <admin-group>:

usermod -aG <admin-group> <user-name>

Replace <admin-group> with the group that is used by the system for sudo access (see above) and <user-name> with you user name.

  • I'm looking into passwordlesssudo. The command: Cmnd_Alias VAGRANT_HOSTMANAGER_UPDATE = /bin/cp <home-directory>/.vagrant.d/tmp/hosts.local /etc/hosts %<admin-group> ALL=(root) NOPASSWD: VAGRANT_HOSTMANAGER_UPDATE is confusing to me. Where do I put it, on the Vagrant or my mac? – Gregory Schultz Jul 4 '16 at 7:58
  • On your host Mac, you should run sudo visudo command which will open a file for editing and add the line to the appropriate section (order is important, so look for similar lines). ..Just please always use visudo for editing and do not edit /etc/sudoers directly. visudo performs additional checks and will prevent locking yourself out of your machine. – techraf Jul 4 '16 at 8:04
  • Added the command, didn't do anything. Also, sudo nano visudo produced a blank file while sudo visudo wasn't and everytime I try to edit the file, I get a notice asking to open either the read only file or edited. Everything I'm doing is correct so far? – Gregory Schultz Jul 4 '16 at 19:43
  • sudo nano visudo is wrong. Frankly, your last comment is grammatically incomprehensible. – techraf Jul 4 '16 at 20:46
  • Sorry, it was 4AM when I wrote the comment and I'm starting to get frustrated. I have this at the top of the file: Cmnd_Alias VAGRANT_HOSTMANAGER_UPDATE = /bin/cp /home/gregoryschultz/.vagrant.d/tmp/hosts.local /etc/hosts %wheel ALL=(root) NOPASSWD: VAGRANT_HOSTMANAGER_UPDATE. Doesn't do anything. Also I get this message when I edit visudo: – Gregory Schultz Jul 4 '16 at 21:22
0

Alternatively: note what line should be added to the Hosts file, then use Textwrangler to edit the Hosts file: then the permissions are not changed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .