I've stumbled upon surprising (for me) permission behavior on FreeBSD. Let's say I'm operating as non-root user. I create a file, set its permission on read-only and then try to write into it:
$ touch f $ chmod 400 f $ ls -l f -r-------- 1 user wheel f $ echo a >> t t: Permission denied. So far so good. Now I do the same as root and it writes into the file:
# ls -l f2 -r-------- 1 root wheel f2 # echo a >> f2 # echo $? 0 Is it a bug or intended behavior? Can I safely assume that this would work so on any Unix & Linux?
CAP_DAC_OVERRIDEcan do this. On nearly all Linux systems this means root can do this so it's intentional. Can't speak for the FreeBSD part but I'd imagine they have a similar setup.chmodcannot write to the file.touch somefile; chmod 0000 somefile; chmod 0644 somefileas a normal user.