How to password protect hosts file

Discussion in 'Mac Basics and Help' started by jamesg1985, Jan 11, 2015.

  1. jamesg1985 macrumors newbie

    Jan 11, 2015
    Hi, I'd like to password protect my hosts file, so it cannot be edited using terminal or any other means. Does anybody have a solution? Thanks, James
  2. doynton macrumors 6502

    Oct 19, 2014
    by default only root can write to hosts file

    adams-mbp:etc adam$ ls -l /etc/hosts
    -rw-r--r-- 1 root wheel 235 30 Nov 18:07 /etc/hosts

    so unless you use sudo you can't update it. If you create a user that is not an administrator then unless you add the user to /etc/sudoers then you will not be able to use sudo and will not be able to update it.
  3. mfram macrumors 65816

    Jan 23, 2010
    San Diego, CA USA
    You could set the system immutable flag. While the flag is set, not even root can modify the file. That would require someone with using sudo to turn off that flag first before it could be modified. It would at least be an extra step that's not very common.

    To set the immutable flag:
    sudo chflags schg /etc/hosts
    To turn off the flag:
    sudo chflags noschg /etc/hosts

Share This Page