Ubuntu – the difference between primary group and secondary group in Ubuntu

groups

What is the difference between primary group and secondary group in Ubuntu?

Best Answer

The primary group is the group applied to you when you log in using the usual methods (TTYs, GUI, SSH, etc.).

Since processes usually inherit the group of the parent, and your initial process or shell would have your primary group as the group, anything you do usually has the effect of the primary group on it (creating files, for example).

The secondary groups are the groups you can start processes as without using a group password, either via sg or to log in to via the newgrp command.

So if you have a primary group x and a secondary group y,

touch foo

will usually create a file with x as the group owner (unless the parent directory is SETGID to another group). However, you can do:

sg y 'touch bar'
# or
newgrp y
touch baz

Then bar and baz will be created with y as the group.

However, if you don't have a group in your secondary groups (say z), the sg and newgroup commands will ask for the group password if you use them with z.