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.

  • Exactly what command you typed? chmod.. – Lucio Aug 4 '12 at 21:02
  • sudo chmod 0 /mnt/myharddisk/etc/ – Richard Nixon Aug 4 '12 at 21:09

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.

| improve this answer | |
  • 1
    Thanks, I just understood what my problem was. I forgot that --- --- --- represents User, Group and Others rather than Root, User and Others..... Also here is a solution on how to protect files from accidental root access: superuser.com/a/104022 – Richard Nixon Aug 4 '12 at 21:54
  • 2
    Excellent. I'm glad Lucio's answer was of help. I should note that more UID doesn't usually mean less capabilities--it's not that simple. It is just that UID 0, root is special. The match between file permissions and the owner and group a file belongs to, and any other access controls, determine access. File ownership can be changed with chown, and group ownership by chgrp. Generally the more groups a user belongs to the wider access they will have. Here's a reference: askubuntu.com/questions/83/how-do-file-permissions-work – John S Gruber Aug 5 '12 at 1:45
  • @JohnSGruber Great comment. I should put my answer as community wiki. This would have been more useful. Am I still in time? – Lucio Aug 5 '12 at 1:50
  • Anyone can either edit anyone's question or answer, or at least suggest an edit by clicking on edit--no need to make it a community wiki item. I'm not sure you understand the UID stuff, though. It's easy to change the owner (represented by the owner's UID) of a file with chown, but one shouldn't change the UID associated with a username. One shouldn't generally change the passwd file directly, instead use commands or the gui to add users and groups and adjust permissions. That way everything matches up. – John S Gruber Aug 5 '12 at 2:14
  • 1
    @RichardNixon, excellent addition about chattr +i. I tested that and got it to work. No need to add your by-line to the text of your changes. It just makes the answer longer. The AskUbuntu site will keep track of what Lucio said and any edits anyone else makes. Click on the time of the last edit to see the history of edits. Thanks to you both. – John S Gruber Aug 5 '12 at 2:19

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.

| improve this answer | |

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.