Primary and secondary groups

grouppermissionsusers

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

Best Answer

  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)
    
Related Question