Can Root/Superuser Read My Read-Protected Files? – Security Insights

permissionsrootSecurity

On shared unix hosting, if I have a file sensitive-data.txt and I issue:

chmod 600 sensitive-data.txt

Can root user still read my file? Specifically I'm wondering if it's safe to store my password in mercurial hgrc file.

UPDATE

Decided to use the mecurial keyring extension as it was super easy to setup:

pip install mercurial_keyring

and then add to hgrc:

[extensions]
mercurial_keyring =

However I'm still interested in the answer to this question.

Best Answer

Yes, root can:

$ echo Hello you\! > file
$ chmod 600 file
$ ls -l file
-rw------- 1 terdon terdon 11 Feb 27 02:14 file
$ sudo -i
# cat file
Hello you!

In any case, even if root couldn't read your files as root, they can always log in as you without a password:

$ whoami
terdon
$ sudo -i
[sudo] password for terdon: 
# whoami 
root
# su - terdon
$ whoami
terdon

So, root can change to any other username using su (or sudo -iu username) and will then be able to do anything at all as though they were you.

Related Question