8

Whe I do ls -l, two of the fields are username of the owner and name of the owning group.

The username is clear - I created the file, it is mine. However the group entry confuses me. My user is a member of several groups. What is so special about the group with the name same as my username, that it owns newly created files and not some other group e.g. sudoers.

0
7

The group entry comes from your primary group, which, by default, is the same as your username.

A new user is assigned to his/her own group which contains only him, hence its called private group. So, until a user deliberately changes the group ownership of a file, it will belong to the user as owner and private group as group owner. http://linuxers.org/article/difference-between-primary-and-secondary-groups-linux

3
  • 3
    The answer is only partially true. The question do not talk about Linux. There are versions of Unix that use the group users, OS X uses staff. Also for Linux, not all distributions use a primary group containing the single given user. – enzotib Aug 7 '13 at 10:32
  • I added the tag linux. So there are primary and secondary groups. Interesting. – Vorac Aug 7 '13 at 11:35
  • 2
    @Vorac: the tag linux does not correct the error: the primary group is not always a group containing only the given user. – enzotib Aug 7 '13 at 17:25
3

Among the metadata kept by traditional unix systems for a file, there is:

  • a user ID identifying the owner of the file;
  • a group ID identifying the group that owns the file;
  • permission bits for the user, for the owning group, and for others.

The sole effect of the group ID of a file (except for directories as described below) is to determine effective permissions. When a process tries to access a file:

  • if that process is running as the user owning the file, user permissions apply;
  • otherwise, if the process has the group owning the file as one of its effective or supplementary groups, then group permissions apply;
  • otherwise “others” permissions apply.

Many modern unices support access control lists which extend on these rules.

When a file is created, its owner is set to the effective user ID of the process that created it. One of two rules are applied to determine the group owning the file:

  • BSD semantics: the file belongs to the group owning the directory;
  • System V semantics: the file belongs to the effective group ID of the process that created it.

Linux and many other modern unices apply System V semantics unless the group has the setgid bit set, in which case BSD semantics are applied. The owner and group can of course be changed later with chown or chgrp.

Normally the effective group ID of a process is the primary group of the user who started the process. This is the group listed in /etc/passwd, if using a local user database. On Linux, you can see it with getenv passwd $USER where $USER is your username (or any other username). The primary group ID is the fourth colon-delimited field.

Depending on your distribution, by default, either all users are in the same group (commonly called users), or each user gets his own group of the same name as the user. Enterprise networks often sort users into groups according to which department they work for or which role they have, e.g. accounting, it, students, etc.

1
  • Giles' answer highlights a new concept for users coming from Windows systems: "otherwise, if the process has the group owning the file as one of its effective or supplementary groups, then group permissions apply;" It is a new concept to me that a process belongs to one or more groups, or that it has an effective group ID. – brentlightsey Aug 7 '15 at 16:58
1

Are you asking how or why?

You can change the group permission using chown :mygroup myfile though more commonly chown myuser:mygroup myfile.

Why is more complicated but involves the ability to set permissions to a group which may contain many users. An example of this is the wheel group that is [often] given permissions in the sudoeors file to run sudo.

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.