File owner must belong to file group

grouppermissions

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.

Best Answer

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.

Related Question