Every user account in Linux belongs to a mandatory primary group and an optional secondary group(s). Why do we need the distinction ?
When a user account is created using either of the commands: adduser
or useradd
, the default is to create the user account with a primary group that has the same name as the username.
Example
Create a user: jhonsudo adduser jhon
Check the groups of the new usergroups jhon
output:jhon: jhon
And the following will add the user to two secondary groups: group1 and group2sudo usermod -aG group1,group2 jhon
Now the user belongs to the groups: jhon, group1 and group2
And, let us say, the user creates a file touch myfile.txt
. What will be the group owner of this text file? The distinction between primary and secondary user groups serves to make the decision. And in this case, the primary group: jhon will be the group owner of the file.