Linux – Primary vs secondary groups in Linux

grouplinuxpermissions

What is the difference between the primary and secondary group?
Why is there a need for a primary group?

Are the user's permissions the same as the primary group permission?

Assume there is a user A with primary group grp1 and user B with primary group grp2 and secondary group grp1. Then can B have the same permission as A for the files created by A?

Best Answer

What is difference between primary and secondary group? What is the need of primary group ?

From Unix Groups:

Primary group – Specifies a group that the operating system assigns to files that are created by the user. Each user must belong to a primary group.

Secondary groups – Specifies one or more groups to which a user also belongs. Users can belong to up to 15 secondary groups.

What is the need of primary group ? Are the user's permissions the same as primary group permission?

Imagine there is no primary group assigned to my User and I'm in 10 secondary groups. I create a new file... what group this file belongs to? which one of these 10? primary group tackles this issue and defines which group the file belongs to by default. You don't want the files you are creating in your home directory to be owned by development group so anyone on that group can do the stuff allowed to do with them as the group.

Assume there is a user A with primary group grp1 and user B with primary group grp2 and secondary group grp1. Then can he have same permission as A for the files created by A ?

No! only permissions defined by group part. Of course it is possible to do it. Using umask for example.

Related Question