How to add existing user to an existing group?











up vote
591
down vote

favorite
191












I want to add the Apache user (www-data) to the audio group. I've read the man page for useradd, but I'm not having any luck. I'm running xubuntu 11.10. Here's what I'm doing:



$ sudo useradd -G audio www-data
useradd: user 'www-data' already exists


If I leave out the -G option, bash, prints the help info for useradd:



$ sudo useradd  audio www-data
Usage: useradd [options] LOGIN
Options: -b, --base-dir BASE_DIR base directory for the home directory...


It's not clear to me from the man page what options I should use to make this work.










share|improve this question




























    up vote
    591
    down vote

    favorite
    191












    I want to add the Apache user (www-data) to the audio group. I've read the man page for useradd, but I'm not having any luck. I'm running xubuntu 11.10. Here's what I'm doing:



    $ sudo useradd -G audio www-data
    useradd: user 'www-data' already exists


    If I leave out the -G option, bash, prints the help info for useradd:



    $ sudo useradd  audio www-data
    Usage: useradd [options] LOGIN
    Options: -b, --base-dir BASE_DIR base directory for the home directory...


    It's not clear to me from the man page what options I should use to make this work.










    share|improve this question


























      up vote
      591
      down vote

      favorite
      191









      up vote
      591
      down vote

      favorite
      191






      191





      I want to add the Apache user (www-data) to the audio group. I've read the man page for useradd, but I'm not having any luck. I'm running xubuntu 11.10. Here's what I'm doing:



      $ sudo useradd -G audio www-data
      useradd: user 'www-data' already exists


      If I leave out the -G option, bash, prints the help info for useradd:



      $ sudo useradd  audio www-data
      Usage: useradd [options] LOGIN
      Options: -b, --base-dir BASE_DIR base directory for the home directory...


      It's not clear to me from the man page what options I should use to make this work.










      share|improve this question















      I want to add the Apache user (www-data) to the audio group. I've read the man page for useradd, but I'm not having any luck. I'm running xubuntu 11.10. Here's what I'm doing:



      $ sudo useradd -G audio www-data
      useradd: user 'www-data' already exists


      If I leave out the -G option, bash, prints the help info for useradd:



      $ sudo useradd  audio www-data
      Usage: useradd [options] LOGIN
      Options: -b, --base-dir BASE_DIR base directory for the home directory...


      It's not clear to me from the man page what options I should use to make this work.







      users groups






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 15 '17 at 18:22









      Simón

      355118




      355118










      asked Nov 15 '11 at 18:21









      Sparky1

      4,02971514




      4,02971514






















          7 Answers
          7






          active

          oldest

          votes

















          up vote
          915
          down vote



          accepted










          The useradd command will try to add a new user. Since your user already exists this is not what you want.



          Instead: To modify an existing user, like adding that user to a new group, use the usermod command.



          Try this:



          sudo usermod -a -G groupName userName


          The user will need to log out and log back in to see their new group added.




          • The -a (append) switch is essential. Otherwise, the user will be removed from any groups, not in the list.


          • The -G switch takes a (comma-separated) list of additional groups to assign the user to.







          share|improve this answer



















          • 67




            sudo usermod -a -G [group-name] [user-name] : Just a quickie for those who only glance at the answer after reading the headline
            – Programster
            Nov 11 '13 at 14:50








          • 34




            I think the preferred way now is sudo adduser user group. It is simpler and cleaner syntax. See the response from @Bai.
            – ctbrown
            Aug 14 '14 at 14:20








          • 3




            @wilhil: man usermod: "-a, --append - Add the user to the supplementary group(s). Use only with the -G option.; -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] [...] If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list."
            – Adam Michalik
            Jan 26 '16 at 15:03






          • 15




            Is there a way to get around the "logout and back in" part? Some type of update-groups command, maybe?
            – con-f-use
            Mar 19 '16 at 0:05






          • 9




            @con-f-use, if you can run sudo login -f YOURUSERNAME, it will start a new shell session. Use the id command to verify that the new session is in the correct set of groups. However, this isn't "global" - it doesn't apply to terminals that are already open. So, really, logging out is the best option, where possible
            – Aaron McDaid
            Mar 31 '17 at 14:57




















          up vote
          198
          down vote













          Adding a user to a group:



          sudo adduser user group


          Removing a user from a group:



          sudo deluser user group





          share|improve this answer

















          • 2




            not exactly what this question being asked for
            – Tejendra
            Sep 3 '14 at 8:10






          • 11




            @Tejendra's comment seems to presuppose that using useradd is desirable/mandatory to answer OP's question; Perhaps this answer is just missing words to indicate that adduser/deluser is a better alternative.
            – sage
            Jul 28 '15 at 19:39






          • 11




            For me simpler interface is better, that's why I like this one.
            – Betlista
            Aug 11 '16 at 10:35






          • 4




            This is exactly the question being asked. @knocte, yes, I think it is Debian specific
            – Auspex
            Nov 14 '16 at 12:58








          • 2




            @Auspex I can confirm that it does not work on Red Hat.
            – Stibu
            Feb 22 '17 at 9:43


















          up vote
          48
          down vote













          After adding to a existing user:



          usermod -a -G group user  


          You may need to logout and login to get the groups permissions from /etc/group.






          share|improve this answer



















          • 21




            Please make it the part "need to logout and login" bold.
            – Jin Kwon
            Dec 17 '13 at 6:36










          • FYI: I think the id command should indicate you were added to the group without needing to exit. id myuser
            – ficuscr
            Jan 3 '14 at 16:57






          • 5




            Logging out and back in was required for me on Ubuntu 14.10.
            – A.Danischewski
            Apr 1 '15 at 0:32


















          up vote
          25
          down vote













          I normally use



          sudo gpasswd -a myuser mygroup





          share|improve this answer

















          • 3




            usermod was not available on my system ubuntu 14.04. This worked great!
            – Drew
            Jun 24 '14 at 15:45


















          up vote
          5
          down vote













          On Ubuntu, since logging in as root is not enabled, users in the sudo group can elevate privileges for certain restricted commands. Any restricted command must be prepended with sudo to elevate privilege.



          sudo usermod -a -G group user


          will add the existing user user to a supplemental group named group. The user's primary group will remain unchanged.






          share|improve this answer






























            up vote
            4
            down vote













            I'm posting this as an answer because I don't have enough reputation to comment. As @dpendolino's mentioned, for the effects of this command to persist:



            sudo usermod -a -G groupName userName



            ...you need to logout/login again.



            However, if you need a shortcut to start using your new group membership immediately (and you have the correct sudo privileges) I have found this work-around:



            $ sudo su -
            # su [userName]
            $ groups


            Explanation:





            • sudo su - will give you a root shell


            • su [userName] returns you to a shell with your user


            • groups when run now will show the group you added with the usermod -aG command


            In my case I was trying to add the 'docker' group to my user



            Before:



            $ groups
            userName adm cdrom sudo dip plugdev lpadmin sambashare wireshark lxd


            After:



            $ groups
            userName adm cdrom sudo dip plugdev lpadmin sambashare wireshark lxd docker





            share|improve this answer




























              up vote
              0
              down vote













              sudo usermod -a -G groupName userName


              will work just fine, but I had to reboot entirely, just log out and log in again did not do the job...






              share|improve this answer








              New contributor




              alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.


















                Your Answer








                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "89"
                };
                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',
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                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%2faskubuntu.com%2fquestions%2f79565%2fhow-to-add-existing-user-to-an-existing-group%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                7 Answers
                7






                active

                oldest

                votes








                7 Answers
                7






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                915
                down vote



                accepted










                The useradd command will try to add a new user. Since your user already exists this is not what you want.



                Instead: To modify an existing user, like adding that user to a new group, use the usermod command.



                Try this:



                sudo usermod -a -G groupName userName


                The user will need to log out and log back in to see their new group added.




                • The -a (append) switch is essential. Otherwise, the user will be removed from any groups, not in the list.


                • The -G switch takes a (comma-separated) list of additional groups to assign the user to.







                share|improve this answer



















                • 67




                  sudo usermod -a -G [group-name] [user-name] : Just a quickie for those who only glance at the answer after reading the headline
                  – Programster
                  Nov 11 '13 at 14:50








                • 34




                  I think the preferred way now is sudo adduser user group. It is simpler and cleaner syntax. See the response from @Bai.
                  – ctbrown
                  Aug 14 '14 at 14:20








                • 3




                  @wilhil: man usermod: "-a, --append - Add the user to the supplementary group(s). Use only with the -G option.; -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] [...] If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list."
                  – Adam Michalik
                  Jan 26 '16 at 15:03






                • 15




                  Is there a way to get around the "logout and back in" part? Some type of update-groups command, maybe?
                  – con-f-use
                  Mar 19 '16 at 0:05






                • 9




                  @con-f-use, if you can run sudo login -f YOURUSERNAME, it will start a new shell session. Use the id command to verify that the new session is in the correct set of groups. However, this isn't "global" - it doesn't apply to terminals that are already open. So, really, logging out is the best option, where possible
                  – Aaron McDaid
                  Mar 31 '17 at 14:57

















                up vote
                915
                down vote



                accepted










                The useradd command will try to add a new user. Since your user already exists this is not what you want.



                Instead: To modify an existing user, like adding that user to a new group, use the usermod command.



                Try this:



                sudo usermod -a -G groupName userName


                The user will need to log out and log back in to see their new group added.




                • The -a (append) switch is essential. Otherwise, the user will be removed from any groups, not in the list.


                • The -G switch takes a (comma-separated) list of additional groups to assign the user to.







                share|improve this answer



















                • 67




                  sudo usermod -a -G [group-name] [user-name] : Just a quickie for those who only glance at the answer after reading the headline
                  – Programster
                  Nov 11 '13 at 14:50








                • 34




                  I think the preferred way now is sudo adduser user group. It is simpler and cleaner syntax. See the response from @Bai.
                  – ctbrown
                  Aug 14 '14 at 14:20








                • 3




                  @wilhil: man usermod: "-a, --append - Add the user to the supplementary group(s). Use only with the -G option.; -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] [...] If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list."
                  – Adam Michalik
                  Jan 26 '16 at 15:03






                • 15




                  Is there a way to get around the "logout and back in" part? Some type of update-groups command, maybe?
                  – con-f-use
                  Mar 19 '16 at 0:05






                • 9




                  @con-f-use, if you can run sudo login -f YOURUSERNAME, it will start a new shell session. Use the id command to verify that the new session is in the correct set of groups. However, this isn't "global" - it doesn't apply to terminals that are already open. So, really, logging out is the best option, where possible
                  – Aaron McDaid
                  Mar 31 '17 at 14:57















                up vote
                915
                down vote



                accepted







                up vote
                915
                down vote



                accepted






                The useradd command will try to add a new user. Since your user already exists this is not what you want.



                Instead: To modify an existing user, like adding that user to a new group, use the usermod command.



                Try this:



                sudo usermod -a -G groupName userName


                The user will need to log out and log back in to see their new group added.




                • The -a (append) switch is essential. Otherwise, the user will be removed from any groups, not in the list.


                • The -G switch takes a (comma-separated) list of additional groups to assign the user to.







                share|improve this answer














                The useradd command will try to add a new user. Since your user already exists this is not what you want.



                Instead: To modify an existing user, like adding that user to a new group, use the usermod command.



                Try this:



                sudo usermod -a -G groupName userName


                The user will need to log out and log back in to see their new group added.




                • The -a (append) switch is essential. Otherwise, the user will be removed from any groups, not in the list.


                • The -G switch takes a (comma-separated) list of additional groups to assign the user to.








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 18 '17 at 22:41









                Sameer

                1131




                1131










                answered Nov 15 '11 at 18:33









                dpendolino

                9,4141106




                9,4141106








                • 67




                  sudo usermod -a -G [group-name] [user-name] : Just a quickie for those who only glance at the answer after reading the headline
                  – Programster
                  Nov 11 '13 at 14:50








                • 34




                  I think the preferred way now is sudo adduser user group. It is simpler and cleaner syntax. See the response from @Bai.
                  – ctbrown
                  Aug 14 '14 at 14:20








                • 3




                  @wilhil: man usermod: "-a, --append - Add the user to the supplementary group(s). Use only with the -G option.; -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] [...] If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list."
                  – Adam Michalik
                  Jan 26 '16 at 15:03






                • 15




                  Is there a way to get around the "logout and back in" part? Some type of update-groups command, maybe?
                  – con-f-use
                  Mar 19 '16 at 0:05






                • 9




                  @con-f-use, if you can run sudo login -f YOURUSERNAME, it will start a new shell session. Use the id command to verify that the new session is in the correct set of groups. However, this isn't "global" - it doesn't apply to terminals that are already open. So, really, logging out is the best option, where possible
                  – Aaron McDaid
                  Mar 31 '17 at 14:57
















                • 67




                  sudo usermod -a -G [group-name] [user-name] : Just a quickie for those who only glance at the answer after reading the headline
                  – Programster
                  Nov 11 '13 at 14:50








                • 34




                  I think the preferred way now is sudo adduser user group. It is simpler and cleaner syntax. See the response from @Bai.
                  – ctbrown
                  Aug 14 '14 at 14:20








                • 3




                  @wilhil: man usermod: "-a, --append - Add the user to the supplementary group(s). Use only with the -G option.; -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] [...] If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list."
                  – Adam Michalik
                  Jan 26 '16 at 15:03






                • 15




                  Is there a way to get around the "logout and back in" part? Some type of update-groups command, maybe?
                  – con-f-use
                  Mar 19 '16 at 0:05






                • 9




                  @con-f-use, if you can run sudo login -f YOURUSERNAME, it will start a new shell session. Use the id command to verify that the new session is in the correct set of groups. However, this isn't "global" - it doesn't apply to terminals that are already open. So, really, logging out is the best option, where possible
                  – Aaron McDaid
                  Mar 31 '17 at 14:57










                67




                67




                sudo usermod -a -G [group-name] [user-name] : Just a quickie for those who only glance at the answer after reading the headline
                – Programster
                Nov 11 '13 at 14:50






                sudo usermod -a -G [group-name] [user-name] : Just a quickie for those who only glance at the answer after reading the headline
                – Programster
                Nov 11 '13 at 14:50






                34




                34




                I think the preferred way now is sudo adduser user group. It is simpler and cleaner syntax. See the response from @Bai.
                – ctbrown
                Aug 14 '14 at 14:20






                I think the preferred way now is sudo adduser user group. It is simpler and cleaner syntax. See the response from @Bai.
                – ctbrown
                Aug 14 '14 at 14:20






                3




                3




                @wilhil: man usermod: "-a, --append - Add the user to the supplementary group(s). Use only with the -G option.; -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] [...] If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list."
                – Adam Michalik
                Jan 26 '16 at 15:03




                @wilhil: man usermod: "-a, --append - Add the user to the supplementary group(s). Use only with the -G option.; -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] [...] If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list."
                – Adam Michalik
                Jan 26 '16 at 15:03




                15




                15




                Is there a way to get around the "logout and back in" part? Some type of update-groups command, maybe?
                – con-f-use
                Mar 19 '16 at 0:05




                Is there a way to get around the "logout and back in" part? Some type of update-groups command, maybe?
                – con-f-use
                Mar 19 '16 at 0:05




                9




                9




                @con-f-use, if you can run sudo login -f YOURUSERNAME, it will start a new shell session. Use the id command to verify that the new session is in the correct set of groups. However, this isn't "global" - it doesn't apply to terminals that are already open. So, really, logging out is the best option, where possible
                – Aaron McDaid
                Mar 31 '17 at 14:57






                @con-f-use, if you can run sudo login -f YOURUSERNAME, it will start a new shell session. Use the id command to verify that the new session is in the correct set of groups. However, this isn't "global" - it doesn't apply to terminals that are already open. So, really, logging out is the best option, where possible
                – Aaron McDaid
                Mar 31 '17 at 14:57














                up vote
                198
                down vote













                Adding a user to a group:



                sudo adduser user group


                Removing a user from a group:



                sudo deluser user group





                share|improve this answer

















                • 2




                  not exactly what this question being asked for
                  – Tejendra
                  Sep 3 '14 at 8:10






                • 11




                  @Tejendra's comment seems to presuppose that using useradd is desirable/mandatory to answer OP's question; Perhaps this answer is just missing words to indicate that adduser/deluser is a better alternative.
                  – sage
                  Jul 28 '15 at 19:39






                • 11




                  For me simpler interface is better, that's why I like this one.
                  – Betlista
                  Aug 11 '16 at 10:35






                • 4




                  This is exactly the question being asked. @knocte, yes, I think it is Debian specific
                  – Auspex
                  Nov 14 '16 at 12:58








                • 2




                  @Auspex I can confirm that it does not work on Red Hat.
                  – Stibu
                  Feb 22 '17 at 9:43















                up vote
                198
                down vote













                Adding a user to a group:



                sudo adduser user group


                Removing a user from a group:



                sudo deluser user group





                share|improve this answer

















                • 2




                  not exactly what this question being asked for
                  – Tejendra
                  Sep 3 '14 at 8:10






                • 11




                  @Tejendra's comment seems to presuppose that using useradd is desirable/mandatory to answer OP's question; Perhaps this answer is just missing words to indicate that adduser/deluser is a better alternative.
                  – sage
                  Jul 28 '15 at 19:39






                • 11




                  For me simpler interface is better, that's why I like this one.
                  – Betlista
                  Aug 11 '16 at 10:35






                • 4




                  This is exactly the question being asked. @knocte, yes, I think it is Debian specific
                  – Auspex
                  Nov 14 '16 at 12:58








                • 2




                  @Auspex I can confirm that it does not work on Red Hat.
                  – Stibu
                  Feb 22 '17 at 9:43













                up vote
                198
                down vote










                up vote
                198
                down vote









                Adding a user to a group:



                sudo adduser user group


                Removing a user from a group:



                sudo deluser user group





                share|improve this answer












                Adding a user to a group:



                sudo adduser user group


                Removing a user from a group:



                sudo deluser user group






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 12 '12 at 13:09









                Bai

                4,4082106




                4,4082106








                • 2




                  not exactly what this question being asked for
                  – Tejendra
                  Sep 3 '14 at 8:10






                • 11




                  @Tejendra's comment seems to presuppose that using useradd is desirable/mandatory to answer OP's question; Perhaps this answer is just missing words to indicate that adduser/deluser is a better alternative.
                  – sage
                  Jul 28 '15 at 19:39






                • 11




                  For me simpler interface is better, that's why I like this one.
                  – Betlista
                  Aug 11 '16 at 10:35






                • 4




                  This is exactly the question being asked. @knocte, yes, I think it is Debian specific
                  – Auspex
                  Nov 14 '16 at 12:58








                • 2




                  @Auspex I can confirm that it does not work on Red Hat.
                  – Stibu
                  Feb 22 '17 at 9:43














                • 2




                  not exactly what this question being asked for
                  – Tejendra
                  Sep 3 '14 at 8:10






                • 11




                  @Tejendra's comment seems to presuppose that using useradd is desirable/mandatory to answer OP's question; Perhaps this answer is just missing words to indicate that adduser/deluser is a better alternative.
                  – sage
                  Jul 28 '15 at 19:39






                • 11




                  For me simpler interface is better, that's why I like this one.
                  – Betlista
                  Aug 11 '16 at 10:35






                • 4




                  This is exactly the question being asked. @knocte, yes, I think it is Debian specific
                  – Auspex
                  Nov 14 '16 at 12:58








                • 2




                  @Auspex I can confirm that it does not work on Red Hat.
                  – Stibu
                  Feb 22 '17 at 9:43








                2




                2




                not exactly what this question being asked for
                – Tejendra
                Sep 3 '14 at 8:10




                not exactly what this question being asked for
                – Tejendra
                Sep 3 '14 at 8:10




                11




                11




                @Tejendra's comment seems to presuppose that using useradd is desirable/mandatory to answer OP's question; Perhaps this answer is just missing words to indicate that adduser/deluser is a better alternative.
                – sage
                Jul 28 '15 at 19:39




                @Tejendra's comment seems to presuppose that using useradd is desirable/mandatory to answer OP's question; Perhaps this answer is just missing words to indicate that adduser/deluser is a better alternative.
                – sage
                Jul 28 '15 at 19:39




                11




                11




                For me simpler interface is better, that's why I like this one.
                – Betlista
                Aug 11 '16 at 10:35




                For me simpler interface is better, that's why I like this one.
                – Betlista
                Aug 11 '16 at 10:35




                4




                4




                This is exactly the question being asked. @knocte, yes, I think it is Debian specific
                – Auspex
                Nov 14 '16 at 12:58






                This is exactly the question being asked. @knocte, yes, I think it is Debian specific
                – Auspex
                Nov 14 '16 at 12:58






                2




                2




                @Auspex I can confirm that it does not work on Red Hat.
                – Stibu
                Feb 22 '17 at 9:43




                @Auspex I can confirm that it does not work on Red Hat.
                – Stibu
                Feb 22 '17 at 9:43










                up vote
                48
                down vote













                After adding to a existing user:



                usermod -a -G group user  


                You may need to logout and login to get the groups permissions from /etc/group.






                share|improve this answer



















                • 21




                  Please make it the part "need to logout and login" bold.
                  – Jin Kwon
                  Dec 17 '13 at 6:36










                • FYI: I think the id command should indicate you were added to the group without needing to exit. id myuser
                  – ficuscr
                  Jan 3 '14 at 16:57






                • 5




                  Logging out and back in was required for me on Ubuntu 14.10.
                  – A.Danischewski
                  Apr 1 '15 at 0:32















                up vote
                48
                down vote













                After adding to a existing user:



                usermod -a -G group user  


                You may need to logout and login to get the groups permissions from /etc/group.






                share|improve this answer



















                • 21




                  Please make it the part "need to logout and login" bold.
                  – Jin Kwon
                  Dec 17 '13 at 6:36










                • FYI: I think the id command should indicate you were added to the group without needing to exit. id myuser
                  – ficuscr
                  Jan 3 '14 at 16:57






                • 5




                  Logging out and back in was required for me on Ubuntu 14.10.
                  – A.Danischewski
                  Apr 1 '15 at 0:32













                up vote
                48
                down vote










                up vote
                48
                down vote









                After adding to a existing user:



                usermod -a -G group user  


                You may need to logout and login to get the groups permissions from /etc/group.






                share|improve this answer














                After adding to a existing user:



                usermod -a -G group user  


                You may need to logout and login to get the groups permissions from /etc/group.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 17 '13 at 7:36









                Jin Kwon

                1127




                1127










                answered Feb 22 '13 at 17:16









                Amos Folarin

                69959




                69959








                • 21




                  Please make it the part "need to logout and login" bold.
                  – Jin Kwon
                  Dec 17 '13 at 6:36










                • FYI: I think the id command should indicate you were added to the group without needing to exit. id myuser
                  – ficuscr
                  Jan 3 '14 at 16:57






                • 5




                  Logging out and back in was required for me on Ubuntu 14.10.
                  – A.Danischewski
                  Apr 1 '15 at 0:32














                • 21




                  Please make it the part "need to logout and login" bold.
                  – Jin Kwon
                  Dec 17 '13 at 6:36










                • FYI: I think the id command should indicate you were added to the group without needing to exit. id myuser
                  – ficuscr
                  Jan 3 '14 at 16:57






                • 5




                  Logging out and back in was required for me on Ubuntu 14.10.
                  – A.Danischewski
                  Apr 1 '15 at 0:32








                21




                21




                Please make it the part "need to logout and login" bold.
                – Jin Kwon
                Dec 17 '13 at 6:36




                Please make it the part "need to logout and login" bold.
                – Jin Kwon
                Dec 17 '13 at 6:36












                FYI: I think the id command should indicate you were added to the group without needing to exit. id myuser
                – ficuscr
                Jan 3 '14 at 16:57




                FYI: I think the id command should indicate you were added to the group without needing to exit. id myuser
                – ficuscr
                Jan 3 '14 at 16:57




                5




                5




                Logging out and back in was required for me on Ubuntu 14.10.
                – A.Danischewski
                Apr 1 '15 at 0:32




                Logging out and back in was required for me on Ubuntu 14.10.
                – A.Danischewski
                Apr 1 '15 at 0:32










                up vote
                25
                down vote













                I normally use



                sudo gpasswd -a myuser mygroup





                share|improve this answer

















                • 3




                  usermod was not available on my system ubuntu 14.04. This worked great!
                  – Drew
                  Jun 24 '14 at 15:45















                up vote
                25
                down vote













                I normally use



                sudo gpasswd -a myuser mygroup





                share|improve this answer

















                • 3




                  usermod was not available on my system ubuntu 14.04. This worked great!
                  – Drew
                  Jun 24 '14 at 15:45













                up vote
                25
                down vote










                up vote
                25
                down vote









                I normally use



                sudo gpasswd -a myuser mygroup





                share|improve this answer












                I normally use



                sudo gpasswd -a myuser mygroup






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '11 at 18:47









                enzotib

                62.1k5130153




                62.1k5130153








                • 3




                  usermod was not available on my system ubuntu 14.04. This worked great!
                  – Drew
                  Jun 24 '14 at 15:45














                • 3




                  usermod was not available on my system ubuntu 14.04. This worked great!
                  – Drew
                  Jun 24 '14 at 15:45








                3




                3




                usermod was not available on my system ubuntu 14.04. This worked great!
                – Drew
                Jun 24 '14 at 15:45




                usermod was not available on my system ubuntu 14.04. This worked great!
                – Drew
                Jun 24 '14 at 15:45










                up vote
                5
                down vote













                On Ubuntu, since logging in as root is not enabled, users in the sudo group can elevate privileges for certain restricted commands. Any restricted command must be prepended with sudo to elevate privilege.



                sudo usermod -a -G group user


                will add the existing user user to a supplemental group named group. The user's primary group will remain unchanged.






                share|improve this answer



























                  up vote
                  5
                  down vote













                  On Ubuntu, since logging in as root is not enabled, users in the sudo group can elevate privileges for certain restricted commands. Any restricted command must be prepended with sudo to elevate privilege.



                  sudo usermod -a -G group user


                  will add the existing user user to a supplemental group named group. The user's primary group will remain unchanged.






                  share|improve this answer

























                    up vote
                    5
                    down vote










                    up vote
                    5
                    down vote









                    On Ubuntu, since logging in as root is not enabled, users in the sudo group can elevate privileges for certain restricted commands. Any restricted command must be prepended with sudo to elevate privilege.



                    sudo usermod -a -G group user


                    will add the existing user user to a supplemental group named group. The user's primary group will remain unchanged.






                    share|improve this answer














                    On Ubuntu, since logging in as root is not enabled, users in the sudo group can elevate privileges for certain restricted commands. Any restricted command must be prepended with sudo to elevate privilege.



                    sudo usermod -a -G group user


                    will add the existing user user to a supplemental group named group. The user's primary group will remain unchanged.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jul 7 '17 at 18:03









                    Eliah Kagan

                    80.9k20226364




                    80.9k20226364










                    answered Feb 25 '16 at 21:58









                    Debra Butcher McCusker

                    5612




                    5612






















                        up vote
                        4
                        down vote













                        I'm posting this as an answer because I don't have enough reputation to comment. As @dpendolino's mentioned, for the effects of this command to persist:



                        sudo usermod -a -G groupName userName



                        ...you need to logout/login again.



                        However, if you need a shortcut to start using your new group membership immediately (and you have the correct sudo privileges) I have found this work-around:



                        $ sudo su -
                        # su [userName]
                        $ groups


                        Explanation:





                        • sudo su - will give you a root shell


                        • su [userName] returns you to a shell with your user


                        • groups when run now will show the group you added with the usermod -aG command


                        In my case I was trying to add the 'docker' group to my user



                        Before:



                        $ groups
                        userName adm cdrom sudo dip plugdev lpadmin sambashare wireshark lxd


                        After:



                        $ groups
                        userName adm cdrom sudo dip plugdev lpadmin sambashare wireshark lxd docker





                        share|improve this answer

























                          up vote
                          4
                          down vote













                          I'm posting this as an answer because I don't have enough reputation to comment. As @dpendolino's mentioned, for the effects of this command to persist:



                          sudo usermod -a -G groupName userName



                          ...you need to logout/login again.



                          However, if you need a shortcut to start using your new group membership immediately (and you have the correct sudo privileges) I have found this work-around:



                          $ sudo su -
                          # su [userName]
                          $ groups


                          Explanation:





                          • sudo su - will give you a root shell


                          • su [userName] returns you to a shell with your user


                          • groups when run now will show the group you added with the usermod -aG command


                          In my case I was trying to add the 'docker' group to my user



                          Before:



                          $ groups
                          userName adm cdrom sudo dip plugdev lpadmin sambashare wireshark lxd


                          After:



                          $ groups
                          userName adm cdrom sudo dip plugdev lpadmin sambashare wireshark lxd docker





                          share|improve this answer























                            up vote
                            4
                            down vote










                            up vote
                            4
                            down vote









                            I'm posting this as an answer because I don't have enough reputation to comment. As @dpendolino's mentioned, for the effects of this command to persist:



                            sudo usermod -a -G groupName userName



                            ...you need to logout/login again.



                            However, if you need a shortcut to start using your new group membership immediately (and you have the correct sudo privileges) I have found this work-around:



                            $ sudo su -
                            # su [userName]
                            $ groups


                            Explanation:





                            • sudo su - will give you a root shell


                            • su [userName] returns you to a shell with your user


                            • groups when run now will show the group you added with the usermod -aG command


                            In my case I was trying to add the 'docker' group to my user



                            Before:



                            $ groups
                            userName adm cdrom sudo dip plugdev lpadmin sambashare wireshark lxd


                            After:



                            $ groups
                            userName adm cdrom sudo dip plugdev lpadmin sambashare wireshark lxd docker





                            share|improve this answer












                            I'm posting this as an answer because I don't have enough reputation to comment. As @dpendolino's mentioned, for the effects of this command to persist:



                            sudo usermod -a -G groupName userName



                            ...you need to logout/login again.



                            However, if you need a shortcut to start using your new group membership immediately (and you have the correct sudo privileges) I have found this work-around:



                            $ sudo su -
                            # su [userName]
                            $ groups


                            Explanation:





                            • sudo su - will give you a root shell


                            • su [userName] returns you to a shell with your user


                            • groups when run now will show the group you added with the usermod -aG command


                            In my case I was trying to add the 'docker' group to my user



                            Before:



                            $ groups
                            userName adm cdrom sudo dip plugdev lpadmin sambashare wireshark lxd


                            After:



                            $ groups
                            userName adm cdrom sudo dip plugdev lpadmin sambashare wireshark lxd docker






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 25 at 17:49









                            bluemorpho

                            512




                            512






















                                up vote
                                0
                                down vote













                                sudo usermod -a -G groupName userName


                                will work just fine, but I had to reboot entirely, just log out and log in again did not do the job...






                                share|improve this answer








                                New contributor




                                alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.






















                                  up vote
                                  0
                                  down vote













                                  sudo usermod -a -G groupName userName


                                  will work just fine, but I had to reboot entirely, just log out and log in again did not do the job...






                                  share|improve this answer








                                  New contributor




                                  alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                  Check out our Code of Conduct.




















                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    sudo usermod -a -G groupName userName


                                    will work just fine, but I had to reboot entirely, just log out and log in again did not do the job...






                                    share|improve this answer








                                    New contributor




                                    alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    sudo usermod -a -G groupName userName


                                    will work just fine, but I had to reboot entirely, just log out and log in again did not do the job...







                                    share|improve this answer








                                    New contributor




                                    alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    share|improve this answer



                                    share|improve this answer






                                    New contributor




                                    alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    answered Nov 26 at 15:34









                                    alex

                                    11




                                    11




                                    New contributor




                                    alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.





                                    New contributor





                                    alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.






                                    alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Ask Ubuntu!


                                        • 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%2faskubuntu.com%2fquestions%2f79565%2fhow-to-add-existing-user-to-an-existing-group%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 did Captain America manage to do this?

                                        迪纳利

                                        南乌拉尔铁路局