4

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?
Stephen Kitt
  • 434,908

2 Answers2

3
  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)
    
heemayl
  • 56,300
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.

tlund
  • 384