0

So I made a file and gave it the following permissions. chmod u-rwx, g=rw, o=rx file

The user can't read the file now, because he doesn't have any read permissions, right?

I could remove the file, why is that? [EDIT: As pointed out by muru, this part of the question is answered here]

But I could still change the permissions of the file. I could give myself the r permission and read it. Why is that?

Thank you!

marked as duplicate by muru, Prvt_Yadav, Gilles 'SO- stop being evil' files Sep 28 at 21:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

In unix-style file permissions, being able to change the permissions is an inalienable part of being the owner of the file: if you are the owner, you can always change the permissions - if you aren't, you can't change the permissions at all. This holds true, no matter what the actual permissions are.

As the owner of the file, you can revoke all the u-permissions, and since the most specific set of permissions takes precedence, you then cannot read the file even if the file was readable to a group you're a member of, or even to everyone else.

Removing a file does not operate on the file itself, but on the directory the file is in: if you have write access to a directory you will be able to delete any file in it, unless the sticky bit (+t) is set on the directory; the sticky bit on a directory will add an extra restriction that prevents anyone from deleting things they don't own. This is usually used in world-writable directories intended for temporary files, like /tmp and /var/tmp.

Normally, if you are not the owner of a file, but have read access to it, and have write access to the directory the file is in, you will be able to gain ownership of the file indirectly, by copying the file, deleting the original and renaming your copy to have the same name as the original file had.

  • Wow! Thank you a lot! This really helped me put everything in order in my head! I feel like I have a greater understanding of the Unix group and user system! – user11212623 Sep 25 at 14:27

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