What is the difference between -g and -G options in useradd

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












7














After I look through the help. I didn't found much difference between them.




-g, --gid GROUP



The group name or number of the user's initial login group. The group
name must exist. A group number must refer to an already existing
group.



-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]



A list of supplementary groups which the user is also a member of.
Each group is separated from the next by a comma, with no intervening
whitespace. The groups are subject to the same restrictions as the
group given with the -g option. The default is for the user to belong
only to the initial group.




If they are the same. Why both they exist?










share|improve this question



















  • 1




    See also: GID, current, primary, supplementary, effective and real group IDs?
    – Satō Katsura
    Jun 29 '16 at 16:49















7














After I look through the help. I didn't found much difference between them.




-g, --gid GROUP



The group name or number of the user's initial login group. The group
name must exist. A group number must refer to an already existing
group.



-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]



A list of supplementary groups which the user is also a member of.
Each group is separated from the next by a comma, with no intervening
whitespace. The groups are subject to the same restrictions as the
group given with the -g option. The default is for the user to belong
only to the initial group.




If they are the same. Why both they exist?










share|improve this question



















  • 1




    See also: GID, current, primary, supplementary, effective and real group IDs?
    – Satō Katsura
    Jun 29 '16 at 16:49













7












7








7


1





After I look through the help. I didn't found much difference between them.




-g, --gid GROUP



The group name or number of the user's initial login group. The group
name must exist. A group number must refer to an already existing
group.



-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]



A list of supplementary groups which the user is also a member of.
Each group is separated from the next by a comma, with no intervening
whitespace. The groups are subject to the same restrictions as the
group given with the -g option. The default is for the user to belong
only to the initial group.




If they are the same. Why both they exist?










share|improve this question















After I look through the help. I didn't found much difference between them.




-g, --gid GROUP



The group name or number of the user's initial login group. The group
name must exist. A group number must refer to an already existing
group.



-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]



A list of supplementary groups which the user is also a member of.
Each group is separated from the next by a comma, with no intervening
whitespace. The groups are subject to the same restrictions as the
group given with the -g option. The default is for the user to belong
only to the initial group.




If they are the same. Why both they exist?







linux permissions useradd






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 20 '18 at 7:21









Rui F Ribeiro

39k1479130




39k1479130










asked Jun 29 '16 at 11:18









Joe.wang

2081614




2081614







  • 1




    See also: GID, current, primary, supplementary, effective and real group IDs?
    – Satō Katsura
    Jun 29 '16 at 16:49












  • 1




    See also: GID, current, primary, supplementary, effective and real group IDs?
    – Satō Katsura
    Jun 29 '16 at 16:49







1




1




See also: GID, current, primary, supplementary, effective and real group IDs?
– Satō Katsura
Jun 29 '16 at 16:49




See also: GID, current, primary, supplementary, effective and real group IDs?
– Satō Katsura
Jun 29 '16 at 16:49










3 Answers
3






active

oldest

votes


















14














-g sets the initial, or primary, group. This is what appears in the group field in /etc/passwd. On many distributions the primary group name is the same as the user name.



-G sets the supplementary, or additional, groups. These are the groups in /etc/group that list your user account. This might include groups such as sudo, staff, etc.






share|improve this answer




















  • Thank you kind and quick help . @roaima Did you mean the primary group (-g) and secondary group(-G)? Thanks.
    – Joe.wang
    Jun 29 '16 at 11:33










  • @Joe.wang yes. "Supplementary", "secondary", and "additional" are names for the same thing. Kusalananda's answer shows this quite clearly with the id command, I think.
    – roaima
    Jun 29 '16 at 11:44










  • Got it ! Thanks your kind help!
    – Joe.wang
    Jun 29 '16 at 11:49


















7














They are not the same. The -g option specifies the "primary" group that a user should belong to, while the -G option specifies one or many supplementary ("secondary") groups.



On a work machine I have access to I have



$ id
uid=1001(me) gid=1001(me) groups=1001(me),27(sudo),110(lxd),1005(theproject)


This shows that my "primary" group is me (same as my username). However, I'm also member of a number of secondary groups.



Membership of the sudo group, for example, allows me to use the sudo command to do scary stuff with the system, due to the way this is configured for sudo in /etc/sudoers on this particular machine.



Membership of the theproject group allows me to modify group-readable/writable files in a project I'm working on with others.



File created will (ordinarily) automatically be assigned to the primary group.






share|improve this answer




























    1














    The group applied via -g is the primary group, so for example when you create a file it will default to making it with your primary group as the group associated with that file. You can however temporarily change which group it uses as default with the sg or newgrp commands. All groups in the -G are secondary groups. More about this here






    share|improve this answer






















      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f292830%2fwhat-is-the-difference-between-g-and-g-options-in-useradd%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      14














      -g sets the initial, or primary, group. This is what appears in the group field in /etc/passwd. On many distributions the primary group name is the same as the user name.



      -G sets the supplementary, or additional, groups. These are the groups in /etc/group that list your user account. This might include groups such as sudo, staff, etc.






      share|improve this answer




















      • Thank you kind and quick help . @roaima Did you mean the primary group (-g) and secondary group(-G)? Thanks.
        – Joe.wang
        Jun 29 '16 at 11:33










      • @Joe.wang yes. "Supplementary", "secondary", and "additional" are names for the same thing. Kusalananda's answer shows this quite clearly with the id command, I think.
        – roaima
        Jun 29 '16 at 11:44










      • Got it ! Thanks your kind help!
        – Joe.wang
        Jun 29 '16 at 11:49















      14














      -g sets the initial, or primary, group. This is what appears in the group field in /etc/passwd. On many distributions the primary group name is the same as the user name.



      -G sets the supplementary, or additional, groups. These are the groups in /etc/group that list your user account. This might include groups such as sudo, staff, etc.






      share|improve this answer




















      • Thank you kind and quick help . @roaima Did you mean the primary group (-g) and secondary group(-G)? Thanks.
        – Joe.wang
        Jun 29 '16 at 11:33










      • @Joe.wang yes. "Supplementary", "secondary", and "additional" are names for the same thing. Kusalananda's answer shows this quite clearly with the id command, I think.
        – roaima
        Jun 29 '16 at 11:44










      • Got it ! Thanks your kind help!
        – Joe.wang
        Jun 29 '16 at 11:49













      14












      14








      14






      -g sets the initial, or primary, group. This is what appears in the group field in /etc/passwd. On many distributions the primary group name is the same as the user name.



      -G sets the supplementary, or additional, groups. These are the groups in /etc/group that list your user account. This might include groups such as sudo, staff, etc.






      share|improve this answer












      -g sets the initial, or primary, group. This is what appears in the group field in /etc/passwd. On many distributions the primary group name is the same as the user name.



      -G sets the supplementary, or additional, groups. These are the groups in /etc/group that list your user account. This might include groups such as sudo, staff, etc.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jun 29 '16 at 11:23









      roaima

      42.8k551116




      42.8k551116











      • Thank you kind and quick help . @roaima Did you mean the primary group (-g) and secondary group(-G)? Thanks.
        – Joe.wang
        Jun 29 '16 at 11:33










      • @Joe.wang yes. "Supplementary", "secondary", and "additional" are names for the same thing. Kusalananda's answer shows this quite clearly with the id command, I think.
        – roaima
        Jun 29 '16 at 11:44










      • Got it ! Thanks your kind help!
        – Joe.wang
        Jun 29 '16 at 11:49
















      • Thank you kind and quick help . @roaima Did you mean the primary group (-g) and secondary group(-G)? Thanks.
        – Joe.wang
        Jun 29 '16 at 11:33










      • @Joe.wang yes. "Supplementary", "secondary", and "additional" are names for the same thing. Kusalananda's answer shows this quite clearly with the id command, I think.
        – roaima
        Jun 29 '16 at 11:44










      • Got it ! Thanks your kind help!
        – Joe.wang
        Jun 29 '16 at 11:49















      Thank you kind and quick help . @roaima Did you mean the primary group (-g) and secondary group(-G)? Thanks.
      – Joe.wang
      Jun 29 '16 at 11:33




      Thank you kind and quick help . @roaima Did you mean the primary group (-g) and secondary group(-G)? Thanks.
      – Joe.wang
      Jun 29 '16 at 11:33












      @Joe.wang yes. "Supplementary", "secondary", and "additional" are names for the same thing. Kusalananda's answer shows this quite clearly with the id command, I think.
      – roaima
      Jun 29 '16 at 11:44




      @Joe.wang yes. "Supplementary", "secondary", and "additional" are names for the same thing. Kusalananda's answer shows this quite clearly with the id command, I think.
      – roaima
      Jun 29 '16 at 11:44












      Got it ! Thanks your kind help!
      – Joe.wang
      Jun 29 '16 at 11:49




      Got it ! Thanks your kind help!
      – Joe.wang
      Jun 29 '16 at 11:49













      7














      They are not the same. The -g option specifies the "primary" group that a user should belong to, while the -G option specifies one or many supplementary ("secondary") groups.



      On a work machine I have access to I have



      $ id
      uid=1001(me) gid=1001(me) groups=1001(me),27(sudo),110(lxd),1005(theproject)


      This shows that my "primary" group is me (same as my username). However, I'm also member of a number of secondary groups.



      Membership of the sudo group, for example, allows me to use the sudo command to do scary stuff with the system, due to the way this is configured for sudo in /etc/sudoers on this particular machine.



      Membership of the theproject group allows me to modify group-readable/writable files in a project I'm working on with others.



      File created will (ordinarily) automatically be assigned to the primary group.






      share|improve this answer

























        7














        They are not the same. The -g option specifies the "primary" group that a user should belong to, while the -G option specifies one or many supplementary ("secondary") groups.



        On a work machine I have access to I have



        $ id
        uid=1001(me) gid=1001(me) groups=1001(me),27(sudo),110(lxd),1005(theproject)


        This shows that my "primary" group is me (same as my username). However, I'm also member of a number of secondary groups.



        Membership of the sudo group, for example, allows me to use the sudo command to do scary stuff with the system, due to the way this is configured for sudo in /etc/sudoers on this particular machine.



        Membership of the theproject group allows me to modify group-readable/writable files in a project I'm working on with others.



        File created will (ordinarily) automatically be assigned to the primary group.






        share|improve this answer























          7












          7








          7






          They are not the same. The -g option specifies the "primary" group that a user should belong to, while the -G option specifies one or many supplementary ("secondary") groups.



          On a work machine I have access to I have



          $ id
          uid=1001(me) gid=1001(me) groups=1001(me),27(sudo),110(lxd),1005(theproject)


          This shows that my "primary" group is me (same as my username). However, I'm also member of a number of secondary groups.



          Membership of the sudo group, for example, allows me to use the sudo command to do scary stuff with the system, due to the way this is configured for sudo in /etc/sudoers on this particular machine.



          Membership of the theproject group allows me to modify group-readable/writable files in a project I'm working on with others.



          File created will (ordinarily) automatically be assigned to the primary group.






          share|improve this answer












          They are not the same. The -g option specifies the "primary" group that a user should belong to, while the -G option specifies one or many supplementary ("secondary") groups.



          On a work machine I have access to I have



          $ id
          uid=1001(me) gid=1001(me) groups=1001(me),27(sudo),110(lxd),1005(theproject)


          This shows that my "primary" group is me (same as my username). However, I'm also member of a number of secondary groups.



          Membership of the sudo group, for example, allows me to use the sudo command to do scary stuff with the system, due to the way this is configured for sudo in /etc/sudoers on this particular machine.



          Membership of the theproject group allows me to modify group-readable/writable files in a project I'm working on with others.



          File created will (ordinarily) automatically be assigned to the primary group.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 29 '16 at 11:28









          Kusalananda

          121k16229372




          121k16229372





















              1














              The group applied via -g is the primary group, so for example when you create a file it will default to making it with your primary group as the group associated with that file. You can however temporarily change which group it uses as default with the sg or newgrp commands. All groups in the -G are secondary groups. More about this here






              share|improve this answer



























                1














                The group applied via -g is the primary group, so for example when you create a file it will default to making it with your primary group as the group associated with that file. You can however temporarily change which group it uses as default with the sg or newgrp commands. All groups in the -G are secondary groups. More about this here






                share|improve this answer

























                  1












                  1








                  1






                  The group applied via -g is the primary group, so for example when you create a file it will default to making it with your primary group as the group associated with that file. You can however temporarily change which group it uses as default with the sg or newgrp commands. All groups in the -G are secondary groups. More about this here






                  share|improve this answer














                  The group applied via -g is the primary group, so for example when you create a file it will default to making it with your primary group as the group associated with that file. You can however temporarily change which group it uses as default with the sg or newgrp commands. All groups in the -G are secondary groups. More about this here







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 13 '17 at 12:22









                  Community

                  1




                  1










                  answered Jun 29 '16 at 11:24









                  Zachary Brady

                  3,406932




                  3,406932



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f292830%2fwhat-is-the-difference-between-g-and-g-options-in-useradd%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown






                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay