What is a Primary Group?
In Linux, every user is associated with a primary group. The primary group is a fundamental concept in Unix-like operating systems, including Linux, and it determines the initial group ownership of files created by the user. When a user creates a file, it is owned by the user’s primary group by default. Each user is a member of one primary group specified in the user’s entry in the /etc/passwd file. The primary group is important because it dictates the default group ownership of files and directories created by the user.
Difference Between Primary Group vs Secondary Group
Basic |
Primary Group |
Secondary Group |
---|---|---|
Definition |
The major group to which a user belongs is known as the primary group. There is exactly one main group for each user. |
In addition to the primary group, a user may also belong to other groups known as secondary groups. Users may be a part of several secondary groupings. |
Default Group Ownership |
By default, the user’s primary group owns any files and directories that are created by the user. |
The ownership of files and folders by default is unaffected by secondary groups. |
Group Permissions |
Establishes the initial group permissions for the user’s generated files and folders. |
Secondary groups don’t affect permissions in that way. The user’s default group and specific file permissions regulate permissions. |
Changing Groups |
Users can change their primary group using the usermod command. |
Users can add themselves to secondary groups using the usermod or useradd commands. |
In /etc/passwd |
Specified in the user’s entry in the /etc/passwd file under the group ID (GID) field. |
secondary group information is stored in the /etc/group file. |
File Creation |
The default ownership setting for files and folders created by the user is the primary group. |
Secondary groups do not affect the user-created files’ default ownership. |
Purpose |
designed to specify the user’s primary affiliation and is frequently applied to collaborative project work. |
used to grant specific permissions or access rights over and beyond what the main group offers. |
Examples |
A primary group named “users” for all regular users |
Secondary groups like “wheel” for administrative access or “audio” for sound-related permissions. |