1

I just wanted to delete most files from an external HD except some certain ones. So I chmod these ones to 0 and did a sudo rm -r ./*. Painfully, the result was that everything got deleted.

Why is that so? ROOT didn't have permission to touch these, but it did anyways. I am confused now.

Lucio
  • 19,191
  • 32
  • 112
  • 191

2 Answers2

0

The chmod command use 4 digits represented as User-Owner-Others-Others, this last one are other users not in the file's group. Each of these can have 4 (read) 2 (write) or 1 (execute), so chmod 0 file do nothing.
If you enter man chmod you can see how it work with the numbers.


INFO ADDED BY @Richard Nixon-
You can't remove permissions to the ROOT but what you can do is protect a file from ROOT, thus any action on this will be in vain. How to:
Enabled --> sudo chattr +i file
Disabled --> sudo chattr -i file


If you read the /etc/passwd file you will see that the ROOT have a UID of 0. If a user have more UID, less permission (access to critical files, programs and more) will have. You can change the UID of a user incrementing or decreasing its permissions. So in this way you could change the permissions of another user to ROOT. How to:
Edit /etc/passwd file with sudo vipw -s and equalizes the user permissions with the ROOT (fist on the list).

More information about the passwd file here and for vipw command type man vipw.

Lucio
  • 19,191
  • 32
  • 112
  • 191
0

When running as root a person or program can do anything on the computer--normal restrictions don't apply. That's the reason that you should be very careful when issuing a sudo command.

John S Gruber
  • 13,436