Why can the root user edit read-only files, but a regular user with sudo access can't?

Solution 1:

Sounds like you're doing something like:

sudo echo "blah blah blah de blah" >> /etc/protected_file

This doesn't work because sudo applies to the echo command, which happily runs as root, but the redirect is part of your current shell, which isn't running as root.

Common solutions are:

sudo bash -c 'echo "blah blah blah de blah" >> /etc/protected_file'

and

echo "blah blah blah de blah" | sudo tee -a /etc/protected_file

Solution 2:

Note: You should be using "visudo" to edit the sudoers file, because it checks the file for syntax errors before letting you commit them, to prevent you from locking yourself out.