20

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

  • Please add more context to your question. Which groups are you asking about? – aquaherd Oct 17 '14 at 9:16
15

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.

4

If you are talking about file system groups, they are pretty well explained here cyberciti article. The primary group is used by default when creating a new file. You can test this

touch foo
ls -la foo

The file will be owned by you and be in your primary group. Users who are also in your primary group will have group level permissions on those files.

You can check your secondary groups with

groups $(whoami)

It also possible to share files with people who are not in your primary group by setting Set Group ID on a directory. This is explained here: shared folder with SetGID.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.