removing write permission does not prevent root from writing to the file
Solution 1:
1) This is a normal behaviour. root has rw access on all files at all times.
2) You can protect a file even from root (not deliberate action, but accidental, anyway) by using
chattr +i filename.ext
That is "change attributes add immutable". To remove the protection:
chattr -i filename.ext
have a look at man chattr
for more info
Solution 2:
Yes, this is normal. Root is god.
-
Yes, there are ways to prevent root from overwriting files.
- Set the immutable bit with
chattr
(+i
sets,-i
unsets). Requires root access, works only on ext2/ext3 (presumably ext4 too), but is otherwise practical. - Don't run apps as root. No root privs, no overwriting files. Use
sudo
to access system functions. - Unmount the filesystem. No mounted fs, no overwriting files. [*]
- Turn off computer. No electricity, no overwriting files.
- Set the immutable bit with
These methods follow logically from #1. As you can see, the last two methods are generally not useful, in the same way that protecting Windows against viruses by unplugging the network is generally not useful. This is why root is dangerous.[+]
[*] Discounting the possibility of "accidentally" writing directly to the block device, of course. Yes, root can do that. Yes, you can prevent that: disconnect the device.
[+] This is also where those BOfH myths come from. They're not all myths.