26

I have a rather simplistic understanding of file permissions on *nix systems. I understand that there is a file owner and file group, but is there a hard and fast rule on whether the said file owner must belong to the file group also? Or put another way, can a file belong to a group that the owner is not a part of?

If so (or if not), why? I'd like to increase my understanding... I can't seem to find anything that specifically talks about this out on the interwebs... I'm also open to some good reading material on the subject.

1 Answer 1

32

No, there's no need for a file's owner to belong to that file's group. There's no mechanism in place for checking or enforcing this. Additionally, a user could belong to a group at one time and then be removed; nothing will go through the filesystem to check for files that would be in conflict.

Basically, the owner and group metadata for a file is just sitting there on the disk, and doesn't have any external links. (Tangent: it's stored by numeric user id and group id, and these are resolved by the system when asked.)

Also, only one set of permissions is ever used at a time — if you are the owner, only owner permissions are looked at and the group permissions don't matter. If you are not the owner but are in the group, group permissions are used. Finally, if you are not in the group nor the owner, the "other" permissions are used. If you are both the owner of a file and in the file's group, the group bits don't matter.

3
  • 1
    Thanks for your answer. This confirms my hunch... I just had a sense that owner trumps group but came across this "rule-of-thumb" at work. Guess it's just one of those monkey see, monkey do thing. Commented Apr 4, 2013 at 18:07
  • 2
    Are you saying that if I'm the owner of a file, and I'm in the group that "owns" it, and the group has permission to write and execute while I only have read permission, then the group permissions will be ignored for me?
    – iconoclast
    Commented May 14, 2013 at 18:52
  • 3
    @iconoclast That is correct. Create a file and type "Hello world" in it. It has your user and group ownership. Then, do a chmod 460 on it and try to edit it. I believe I have read it somewhere but the term used is that the user and group permissions in a Unix file are decoupled.
    – unxnut
    Commented Jun 21, 2013 at 13:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .