So when I look at the permissions of the /etc/sudoers file, it is like so

-r--r----- 1 root root 705 Nov  2 19:57 /etc/sudoers

Now, wouldn't this mean it's not writable? So how does the root user manage to write to it?


The root user has always full write access to any file, regardless of its mode.

Perhaps the best example is /etc/shadow, which is mode 000 but of course modifiable by root:

[root@centos7 ~]# ls -pl /etc/shadow
----------. 1 root root 1353 Oct 26 07:40 /etc/shadow

As stated in the comments the original answer was kind of unclear.

The owner of a file can always change the permissions of any file he owns (while root can do this for all existing files).

If you are a regular user it depends on the way you try to modify the read-only-file:

  • open the file with vi and change it -> you can write the changes with ":w!"
  • try #echo "test" >> read-only-file there is a permission denied.

If you are the root user you can overwrite and change any file you want, but the program vi will consider the read-only-permissions and ask for a confirmation.

The file /etc/sudoers should always be changed by the "visudo"-command, which opens the content of the actual file in a temporary file, and does some checks before saving the changes. As root-User the changes can be written despite the read-only-permissions.


Try to use visudo instead of vi

sudo visudo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.