Tuesday, October 3, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  0] [ 0]  / answers: 1 / hits: 982  / 11 Months ago, thu, december 1, 2022, 9:41:38

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.

More From » permissions


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.

[#36364] Friday, December 2, 2022, 11 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 266
Total Questions: 113
Total Answers: 120

Location: Ecuador
Member since Tue, Jul 26, 2022
1 Year ago