4

So I've got the basics of primary and secondary groups down, but still have some questions I can't seem to find solid answers to:

  1. Can many users belong to the same primary group?
  2. Can one user's primary group be a secondary group of another user?

Thanks

  • 5
    The answers to your questions are "YES" and "YES". – MelBurslan Apr 4 '16 at 13:32
  • The reason you didn't find explicit answers is probably that nobody bothers listing every arbitrary restriction that doesn't exist. – Gilles Apr 4 '16 at 21:47
2
  1. Yes, they can.

    $ id foo
    uid=1002(foo) gid=1002(foo) groups=1002(foo)
    $ id bar
    uid=1003(bar) gid=1003(bar) groups=1003(bar)
    

    Changing the primary group of user foo to bar which is the primary group for user bar:

    $ sudo usermod -g bar foo
    

    Now:

    $ id foo
    uid=1002(foo) gid=1003(bar) groups=1003(bar)
    $ id bar
    uid=1003(bar) gid=1003(bar) groups=1003(bar)
    
  2. Yes, it can be.

    $ id foo
    uid=1002(foo) gid=1002(foo) groups=1002(foo)
    $ id bar
    uid=1003(bar) gid=1003(bar) groups=1003(bar)
    

    Adding user bar to group foo which is the primary group of user foo:

    $ sudo usermod -a -G foo bar
    

    Now:

    $ id foo
    uid=1002(foo) gid=1002(foo) groups=1002(foo)
    $ id bar
    uid=1003(bar) gid=1003(bar) groups=1003(bar),1002(foo)
    
1

From the perspective of the user, he has a primary group and 0 or more secondary groups.

From the perspective of the group, it has 0 or more members.

A group that is the primary group for one or more users can be both a secondary or primary group for other users.

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.