When sudo Fails You08 Mar 2015
I was running the fairly common command to make a read-only file writable and ran into permission issues:
Strange, especially since I own the file:
To appease the permission gods I tried what I most often think is the fix-me for permission problems:
I’m running the command as superuser! Dare defy me.
What is this mysterious power that will not cower even before the superuser? After digging around a bit in the OS X forums I came across this:
“Immutable flags are file system attributes that, when enabled, prohibit changes to objects i.e. lock them. Enabled, immutable flags supersede permissions: you cannot modify an object whose immutable flags have been enabled despite having Read & Write permissions on that object.” -The X Lab
These flags are BSD file flags that are used primarily to limit a file’s use. They often override traditional Unix permissions. The -O option of ls can be used to inspect what file flags are currently enabled:
uchg is the User immutable flag that prevents inadvertent modification to a file at the user level. When uchg is set, it marks the file as immutable preventing it from being changed, moved, or deleted, even by root.
Similarly, there is a flag schg which is the System Immutable Flag which can only be enabled or disabled by the superuser in single user mode.
The uchg file flag can be set or cleared by the owner of the file. To clear the uchg flag on the file, run the chflags command with nouchg:
The uchg flag will have been cleared:
And thus will be restored the balance of power in the universe.