Linux 101 : Local User Groups - Primary and Secondary groups -
Every user on a Linux system have their own primary group. It usually has the same name as their username.
If the user "debian" becomes a member of the group "group_1", he could have "read-write" access to the file "file_1".
Adding a group:
Changing the primary group of a user:
The primary group is used when a user creates a new file "file_1" in our example below:
The user "debian" for example will have as its primary group the "debian" group.
Secondary groups:
Secondary groups are groups that users could belong to in addition to their primary group to have access to other folders.
If the user "debian" becomes a member of the group "group_1", he could have "read-write" access to the file "file_1".
Adding a group:
The below command adds a group named "group_2" to the system:
We use the below command to display the groups a user belongs to:
We see that the "debian" user primary group is "debian", the rest are his secondary groups.
Changing the primary group of a user:
To modify the primary group of a user we use:
Adding new groups to the secondary groups of a user:
To add a new secondary group for a user we use:
Important:
The above command will delete all the secondary groups the user is a member of, it will only keep the newly added group "newgroup".
To avoid the above scenario, we use "-a" option "append":
We can check whether the new group was added using the below command:
The primary group role:
The primary group is used when a user creates a new file "file_1" in our example below:
Comments