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.
Cmnd_Alias VAGRANT_HOSTMANAGER_UPDATE = /bin/cp <home-directory>/.vagrant.d/tmp/hosts.local /etc/hosts
%<admin-group> ALL=(root) NOPASSWD: VAGRANT_HOSTMANAGER_UPDATE
<home-directory> with your actual home directory (e.g.
<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
usermod -aG <admin-group> <user-name>
<admin-group> with the group that is used by the system for sudo access (see above) and
<user-name> with you user name.