Group – Primary Group and Secondary Group
Linux OS has a concept of the group to manage multiple users’ permission settings. There are two types of groups – Primary Group and Secondary Group.
Primary Group
The Primary Group is the main group of the user and it is used for the owner group setting when the user creates a new document. One user can belong to only one Primary Group.
Secondary Group
A Secondary Group is used to manage permissions to certain documents (or commands) as a group. For example, if user_a is a sudo group member on Ubuntu OS (or wheel group on CentOS), user_a can run the sudo
command. Unlike in the Primary Group, one user can belong to multiple Secondary Groups.
New Document Permission Setting
When a user creates a file or directory, that user becomes the owner of that file or directory. That file or directory also defines its owner group. The Primary Group of the owner user is set for the owner group of the file or directory. This means other users in the owner user's Primary Group will have owner group permissions for the file or directory. In this case, other users in a Secondary Group of the owner user are still regarded as others in the document permission setting.
Note: Private Group
As the default setting, each user's Primary Group name is the same name as the user name. This Primary Group is called a Private Group. By having a Private Group, you can avoid giving permissions to unintended users when you create a new document.
For example, the owner group of the home directory is usually a Private Group, which is the same name as the user's name – as shown below.
ls -l /home
drwxr-xr-x 4 ubuntu ubuntu 4096 Jan 2 08:32 ubuntu
drwxr-xr-x 2 user_a user_a 4096 Jan 2 08:32 user_a
drwxr-xr-x 2 user_b user_b 4096 Jan 2 08:32 user_b