sajad torkamani

Every Unix user belongs to exactly one primary group but can also belong to multiple secondary groups.

Primary group

Every user has exactly one primary group which you can see in /etc/passwd. This group is typically created when the user is created and has the same name as the user.

Used for:

  • Assigning group ownership to new files created by a user.

How to view the primary group:

  • View primary group name: id -gn <user>
  • View primary group ID: id -g <user>

Primary group information is stored in etc/passwd.

Secondary group

A user can belong to multiple additional groups in addition to their primary group.

Used for:

  • Used to control what files / resources members of a group can access. See here for more details.

How to view secondary groups

  • View names of secondary groups: groups <user>
  • View IDs of all groups (including primary groupd): id -G <user>

The information is stored in /etc/group.