I don't have permission to edit the hosts file, even if I use sudo and turn off SIP.

I use sudo vim /etc/hosts to open the hosts file. After entering :wq!, it shows:

"hosts" E212: Can't open file for writing

like I am not using sudo.

I also tried using sudo nano /etc/hosts and it said:

[ Cannot open file for writing: Operation not permitted ]

Then I try sudo chflags nouchg /etc/hosts, but it makes no change.

BTW, inside the Finder, there is a lock in the lower-left corner of the hosts file. I try to change the lock status in Get info but the lock icon is not clickable.


1 Answer 1


After I enter sysctl kern.securelevel and sudo chflags noschg /etc/hosts, the schg flag of the hosts file has magically disappeared. Now it is editable!

You must log in to answer this question.

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