Linux Add User To Group Using Command-Line

How can I add a user to a group under Linux operating system using command line options? How to add an existing user into a group in Linux using command line options?

You can use the useradd or usermod commands to add a user to a group. This page explains how to add user to group in Linux using the CLI. The useradd command creates a new user or updates default new user information. The usermod command modifies a user account, and it is useful to add a user to existing groups. There are two types of groups on Linux operating systems:

  1. Primary user group. – It is the group that applied to you when login. Typically it is same as your login name. All of your process and files (including directories/folders) would have your primary group as the group membership. The primary group allows private group membership and security features. Your files or process cannot access by other group members or users on the Linux system.
  2. Secondary or supplementary user group – Users can be a member of other groups on the Linux system. It is useful for file sharing and other purposes. A sysadmin can fine-tune security too. For example, if you are a member of a secondary group called cdrom, you can mount and unmout cd-rom drive.
Tutorial details
Difficulty level Intermediate
Root privileges Yes
Requirements usermod/useradd
Est. reading time 5 minutes

How to add user to group in Linux

Please note that all user accounts related information are stored in the following files:

  1. /etc/passwd – Contains one line for each user account.
  2. /etc/shadow – Contains the password information in encrypted formatfor the system’s accounts and optional account aging information.
  3. /etc/group – Defines the groups on the system.
  4. /etc/default/useradd – This file contains a value for the default group, if none is specified by the useradd command.
  5. /etc/login.defs – This file defines the site-specific configuration for the shadow password suite stored in /etc/shadow file.

We do not modify these files by hand. Instead, we add a user to a group in Linux using various commands.

Linux command to add user to group

Open the terminal and then type:

  1. Add a new user called jerry to secondary group named cartoons on Linux:
    sudo useradd -G cartoons jerry
  2. Want to add a new user called tom to primary group called cartoons? Run:
    useradd -g cartoons tom
  3. We can add a existing user named spike to existing group named cartoons in Linux:
    useradd -g cartoons spike

How to become a root user

You must run all command as root user. To become a root user run:
su -
Alternatively use sudo command:
sudo -i

Add a new user to secondary group using useradd

You need to the useradd command to add new users to existing group (or create a new group and then add user). If group does not exist, create it. The syntax is as follows:
useradd -G {group-name} username
In this example, create a new user called vivek and add it to group called developers. First, make sure group developers exists using grep command:
# grep "^developers" /etc/group
Sample outputs:


If you do not see any output then you need to add group developers using the groupadd command:
# sudo groupadd developers
Verify that user vivek does not exists:
# grep "^vivek" /etc/passwd
You should not see any outputs from above command. Finally, add a new user called vivek to group developers:
# useradd -G developers vivek
Setup password for user vivek:
# passwd vivek
Ensure that user added properly to group developers:
# id vivek
Sample outputs:

uid=1122(vivek) gid=1125(vivek) groups=1125(vivek),1124(developers)

Please note that capital G (-G) option add user to a list of supplementary groups. Each group is separated from the next by a comma, with no intervening whitespace. For example, add user jerry to groups admins, ftp, www, and developers, enter:
# useradd -G admins,ftp,www,developers jerry

How to add a new user to primary group using useradd

To add a user tony to group developers use the following command:
# useradd -g developers tony
# id tony

Linux Add User To Group
Please note that small g (-g) option add user to initial login group (primary group). The group name must exist. A group number must refer to an already existing group.

How to add a existing user to existing group using usermod

Add existing user tony to ftp supplementary/secondary group with the usermod command using the -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option:
# usermod -a -G ftp tony
In this example, change tony user’s primary group to www, enter:
# usermod -g www tony

usermod command options summary

Option Purpose
-a--append Add the user to the supplementary group(s). Use only with the -G option.
--gid GROUP
Use this GROUP as the default group.
-G GRP1,GRP2--groups GRP1,GRP2 Add the user to GRP1,GRP2 secondary group.

A note about security

If you add or delete user to existing group, you must change the owner of any crontab files or at jobs manually. You must make any changes involving NIS on the NIS server too.

A note about GUI tool

You will probably find the use of the GUI tool easy. KDE user can use KUser tool and the GNOME user can use users-admin:

users-admin - Linux Users Administration Tool

users-admin is part of the GNOME system tools, a set of tools to easily access and manage system configuration

One can easily add users as follows from the gnome 3 settings on a Debian/Ubuntu Linux:

Fedora/RHEL/CentOS user can use system-config-users command as follows
# system-config-users
$ ssh -X -t sudo system-config-users

Sample outputs:
Linux add new users with user manager
Click on the Groups tab to add or view groups:
Linux Add User To Group Using GUI Tools

Summing up

You learned how to add a new or existing user to group on Linux operating systems. For more information type the following command at the shell prompt to read man pages:
$ man usermod
$ man useradd

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 133 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
133 comments… add one
  • praj Mar 26, 2006 @ 16:05

    How can i run the passwd command
    non-interactively in linux . I want to change the password through a script file….How can i
    invoke the passwd command thru a script file non-interactively.
    If thats not possible then suggest
    some alternative…

    • manoj May 6, 2011 @ 14:18

      Multiple entries named ‘audio’ in /etc/group. Please fix this with pwck or grpck.
      usermod: error adding new group entry

  • 🐧 nixcraft Mar 26, 2006 @ 20:02

    See shell script example here

  • BackSeat Aug 14, 2006 @ 15:41

    praj: see chpasswd(8)

  • BnK Dec 6, 2006 @ 20:51


    time saving tip for new admin. I can read man page but it is full of shit-load and no examples at all. keep it up good work!

  • Søren Jun 19, 2007 @ 10:37

    I find the easiest way to add a user to a group is using gpasswd like this:
    gpasswd -a

  • Søren Jun 19, 2007 @ 10:38

    This editor bugs me :) The command should be:
    gpasswd -a user group

  • Frogbert Jul 11, 2007 @ 6:52

    This is wrong, usermod -G ftp tony will take you out of all your existing groups. Not add a new one.

  • 🐧 nixCraft Jul 12, 2007 @ 18:13

    Yes I’m adding a existing user to existing group, but to keep user in other old group you need to use:

    usermod -G oldgroup1, oldgroup2, ftp tony
    • lefty.crupps Oct 15, 2014 @ 17:39

      You’re suggesting we’d need to know each group first? Perhaps telling us that above would be good, also including the command to find the current ‘oldgroup1 oldgroup1’ stuff:
      groups lefty

      Also, what’s the difference between useradd and adduser?
      What’s the differences between distros?
      The article could use some reorganization as well to make the concept flow better, but the article has good info, just not laid out super-clearly. IMHO.

  • vim Jul 14, 2007 @ 2:41

    Actually, it’s easier to go like this:

    usermod -a -G ftp tony

    The -a causes your old groups to be kept. At least in the newer versions. I was looking into this and found an old manpage where the -a function is not documented.

    Since I don’t know when this feature was introduced, you should check for it on the man pages before using it.

  • 🐧 nixCraft Jul 14, 2007 @ 22:15


    -a seems to a new option. This FAQ has been updated to include -a.

    Appreciate your post!

    • Themba Mar 16, 2015 @ 8:06

      The -a option is not working on ubuntu 14.04

      • Sterex Jan 30, 2016 @ 13:14

        It works just fine.

  • derry Aug 7, 2007 @ 22:25

    I recommend that when you need to add people to an existing group to use

    gpasswd -a USER GROUP

  • Steve Francia Aug 19, 2007 @ 18:24

    usermod (pwdutils) 3.1.2

    there is no -a option available, so that options is a fairly new one, it also appears to be nonstandard across *NIX.

  • rupa Aug 22, 2007 @ 9:06

    thanks for -a option, it saved my time on centos

    • emiat Feb 1, 2011 @ 4:43

      tnx a lot

    • ratna Dec 16, 2011 @ 11:51

      R u still in same Domain?


  • suresh Jan 7, 2008 @ 12:01

    why this command didnt work on sun solaris 10 ?
    #useradd -u 100 -g other -d /export/home/newuser1 -m -s /bin/ksh -c “Regular User Account ” newuser1

    Error :uid 100 already in use

  • soliver Jan 25, 2008 @ 21:20


    how can I give a usergroup root rights?
    I would like to create a group “developer” but they need root access as well.


    • Ryan Mar 13, 2012 @ 1:13

      No one needs to assign root access to their own account. Not even you. Add them to the wheel group.

  • soliver Jan 25, 2008 @ 21:23

    I also want to give another user root access.
    That way you can do PermitRootLogin yes, which is more secure.

  • Nilesh Jan 26, 2008 @ 15:09

    install sudo.

    then edit /etc/sudoers (or other location)

    and append the line-

    %developer ALL=(ALL) NOPASSWD: ALL

    This will give the users in group developer the root access but will need to type


    The above setup will not demand root password

  • chris Mar 11, 2008 @ 18:47

    Now that I foolishly ran:
    usermod -G ftp chris

    Is there anyway I get access back to all the groups I had before?

    I am using Ubuntu so I don’t have a password for the root user.

  • 🐧 nixCraft Mar 11, 2008 @ 19:31

    See if you have backup in /etc/group- or restore it from your tape backup.


  • chris Mar 11, 2008 @ 19:50

    no tape backup and unless the etc/group file is auto backedup I don’t have one of those either.

  • 🐧 nixCraft Mar 12, 2008 @ 5:28
  • LiLo Apr 30, 2008 @ 8:34


    Is there a way to automatically create a MySQL database when creating the user?

    (the new database would be named after the user and with the same login / password)

  • 🐧 nixCraft Apr 30, 2008 @ 12:48

    You need to write a shell script; there is no built in option to create mysql db.

  • LiLo Apr 30, 2008 @ 14:04

    OK, so for instance, with webmin which allows the creation of users from a text using useradd, it would not be possible to automatically add a database for each call of useradd without modifying webmin…

    That’s not making my life any easier :)

  • toti May 2, 2008 @ 4:19

    Hi… newb here ;)
    I have a quick question: in CentOS 5, when I type usermod -a -G ftp tony I always get the error “invalid numeric argument ‘ftp’ why is that?

  • toti May 2, 2008 @ 4:20

    sorry just read the disclaimer on “leave reply” disregard my question :|

  • RobM Jun 6, 2008 @ 20:27

    If you modified your own user account while logged in with it, the changes will not have an effect until you next login.

    If you don’t want to logout, you can replace your current BASH shell with a new one to achieve the same thing by running the follow:

    su –preserve-environment –command “$(which $SHELL) –login -i” $(whoami)

    This will switch-user to yourself, replacing your current shell with a new instance of itself. You will be prompted for your password.

    If you don’t specify a command to run you’ll probably get an error to the effect of “cannot execute bash: file not found” because it won’t be on the environment. You could use –shell to point su at it, but your shell wouldn’t be a “login” shell and therefore won’t read your .bash_profile etc.

  • kishore Jun 19, 2008 @ 9:58

    Hi friends,

    I want to say thanks for u.Because of this post i created the users myself without anyones help.

    Thanks and Regards

  • helpneeded Jun 26, 2008 @ 11:30

    why do we need to add new users in linux?

  • 🐧 nixCraft Jun 26, 2008 @ 13:31

    Linux is multiuser operating system. User can maintain their privacy and security.

  • HAMEED Jun 27, 2008 @ 9:18


  • itsadok Jul 5, 2008 @ 6:16

    There are simpler commands (at least on Ubuntu):

    adduser user group
    will add an existing user to an existing group

    deluser user group
    will remove a user from a specified group

  • David Brown Jul 6, 2008 @ 21:04

    In the past when I’ve upgraded to the latest edition of Ubuntu I’ve added any existing users by entering the user name, real name, password etc. into the Users and Groups dialogue boxes and all worked fine.

    However with upgrading to Hardy when I do the same an error flags up saying “Home Directory Already Exists – Please enter a different home directory path” and I’ve been unable to re-instate the users.

    Can anyone tell me how to add these users

  • JuLian henDra Jul 8, 2008 @ 4:06

    How do I listed all existing users and group by command line in Ubuntu, thanks

  • vishwas Jul 8, 2008 @ 5:45

    how to add two groups in a group
    for eg: group1 and group2 these group should be added to another group called group3

  • functionsys Aug 21, 2008 @ 5:16

    whyyyyyyyyy how i can fix it

    FunctionSys@FunctionSys-PC ~/mysql
    $ groupadd
    bash: groupadd: command not found

    FunctionSys@FunctionSys-PC ~/mysql
    $ /usr/sbin/groupadd
    bash: /usr/sbin/groupadd: No such file or directory

    FunctionSys@FunctionSys-PC ~/mysql
    $ useradd -G {mysql} mysql
    bash: useradd: command not found

    FunctionSys@FunctionSys-PC ~/mysql

  • Suresh Sep 22, 2008 @ 10:06

    Hi Vivek,

    your tutorial is really nice to follow.

    I have a scenario, where i need to create a super user and subuser(1,2,3) for accessing ftp in our webserver it is linux with redhat on it. so that super user can access all the subuser folders, and subusers can access only their folders respectively.

    I haven’t created any of the groups, so i would like to know from scratch like defining users and creating permissions.

    since I am new to this linux environment, it would be great if you could post commands like the one above for the scenario i explained.

    Many Thanks.

  • eve Oct 22, 2008 @ 13:38

    i have 2 group. Group A and Group B.
    I have a existing user in Group A.
    Now i want to add this existing user to Group B too.
    What should i do?

    Thanks You.

  • Aksuli Oct 31, 2008 @ 21:43

    Ive managed to add account.

    richard@richard-desktop:~$ sudo useradd -G admin,dialout,cdrom,floppy,audio,dip,video,plugdev,fuse,lpadmin aksu
    richard@richard-desktop:~$ sudo passwd aksu
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully
    richard@richard-desktop:~$ id aksu
    uid=1001(aksu) gid=1001(aksu) groups=1001(aksu),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),107(fuse),109(lpadmin),115(admin)

    Now I have a problem, when I connect the server says:

    Could not chdir to home directory /home/aksu: No such file or directory

    How can I manage that to work out right. ATM I can’t use TAB for filling in file/folder names etc.. PLZ help me out :)

  • vishwas Nov 3, 2008 @ 4:00

    Aksuli type this command it will help u

    1) richard@richard-desktop:~$ sudo useradd -G admin,dialout,cdrom,floppy,audio,dip,video,plugdev,fuse,lpadmin aksu -d /home/aksu

    2) mkdir /home/aksu

  • kenny Nov 14, 2008 @ 19:01

    i type in useradd command but i get the response command not found.what is the problem

  • Pratik Patel Nov 15, 2008 @ 5:10

    Please tell me how can i add multiple users to one group at a single shot.

  • Ryan Nov 20, 2008 @ 23:59

    To add a user to multiple groups – ‘man useradd’

    -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.

  • junaid Jan 21, 2009 @ 9:10

    thanks a alot buddy for help……. keep it up

    plz insert search tool with in website…….

    GOD bless YOU

  • hyacinth Feb 4, 2009 @ 3:01

    How to delete and add a group..
    please help me..


  • dunno Feb 13, 2009 @ 21:41

    complete noob with linux here…

    what are the actual groups that you can add users to?

    i know there’s the ‘users’ group for standard users… but what else is there? can i add a user as a sysadmin with full control over the system? or is that the same as logging in as root?

    i also understand it’s apperently a “bad idea” to login as root into KDE… but why?

    sorry, like i said, complete noob. just installed yesterday.

    oh, and also, even though i realize this isn’t the right place to ask this, i have no idea where else to ask and i’ve been seraching for this for hours… how do you mount a new hard drive? there’s plenty of info telling how to mount a cdrom or a floppy drive, or even a usb thumb drive, but NOWHERE does anything or anyone say how to mount a simple hard drive…. is it not possible to add an additional hard drive? i can’t believe that that would be impossible, so there’s got to be a way.

  • wasim Mar 9, 2009 @ 12:14

    to add user in multiple group

    usermod -G group1,group2 username

  • Patrick Mar 29, 2009 @ 18:04

    i have 3 sites. MainSite TestSite and FileSite. Main and Test need to be apart of the FileSite group to be able to read/write/delete files.

    usermod -a -G MainSite,TestSite FileSite
    is that right?

  • Aheebwa Edgar May 19, 2009 @ 18:16

    pliz thanx so much for your ideas but my question was how to add one user to the linux waiting right now.
    God bless you

  • Aheebwa Edgar May 19, 2009 @ 18:46

    i need just a command to add user to a group.thank you

  • Snap Jun 5, 2009 @ 2:44

    If I have a user that is only used to run scripts (started by fetchmail), but I do not actually ever log in as such user in the console. I have added that user to a group to get access to a folder, but it does not seem to work.. if it was a normal user, I would simply log out and log in again to activate my membership in this group.. but since I never log in with this user, how can I make sure that it is actually a member of the group?

  • balu phani Jul 29, 2009 @ 6:18

    i want to create a user say “testusr” and i don’t want to get home directory for him and his individual group (generally he will belong to his group “testusr” group i don’t want it) but i have already have a common group say “cmngrp” so he should belong to it only.
    i think my point is clear
    create “testusr” without home directory and without his own group but belongs to “cmngrp”.

  • balu phani Jul 29, 2009 @ 7:29

    i got it
    useradd -Ng -M

  • wasim Jul 29, 2009 @ 11:38

    you can check existing group by this command

    cat /etc/group | cut -d “:” -f1

  • yogesh kolte Oct 28, 2009 @ 8:29

    it was very helpful to usermod command to modified changes the user

  • Vlad the Impaler Nov 8, 2009 @ 9:26

    To check groups and who is in the group, the easiest is cat /etc/group. Smile!

  • karim Nov 21, 2009 @ 9:18

    Hi ,

    Say i have a group called music.

    I want every new user henceforth created to automatically have the music group as their secondary group on top of the primary group that will be added by the system.

    Is this possible?


  • Al B.. Jan 15, 2010 @ 20:56

    son of monkeys uncle there is no usermod “-a” option is SUSE Ent 10

  • esraa Mar 24, 2010 @ 19:47


  • esraa Mar 28, 2010 @ 19:31

    i wante cleared code in shell script programming to add user and add groupe

  • zerc May 5, 2010 @ 14:15


    Thank you for this tutorial !

  • Arvind May 19, 2010 @ 5:37

    Thank you for this tutorial !

  • umer ahmed Jun 5, 2010 @ 17:39

    good tutorial

  • Andey Jun 5, 2010 @ 22:16

    i’ve probably used this page like 50 times because i’m still to lazy to learn usermod

  • Brian Maskell Jun 9, 2010 @ 19:11
  • uzer Jul 4, 2010 @ 19:51

    Hey, I’m getting
    [user@localhost ~]$ sudo su
    [sudo] password for user:
    user is not in the sudoers file. This incident will be reported.

  • shane williamson Jul 7, 2010 @ 2:03

    Okay these commands DO NOT WORK!!!!!!!!!!!!!!

  • indir Jul 9, 2010 @ 6:25

    thanks, its works for me :)

  • selven Sep 15, 2010 @ 19:44

    seriously, this is so gay! in my days to add a user to a group, we just had to add it in /etc/group! i don’t understand why there should be a “tool” to complicate it!

  • nic Sep 16, 2010 @ 14:49

    I like to use a “for” loop for this. For exampled

    for i in group1 group2 group3 ...; do adduser $i; done

  • Tom O'Connell Oct 7, 2010 @ 15:22

    I am using Mint 9 and have no knowledge of either command line or archive manager.
    Can you steer me to the easiest tutorial.


  • dx Nov 4, 2010 @ 10:06

    how many users can be in a group? i want to add 500 users to group mailusers. wont that be slowing down my mailserver?


  • syed Dec 9, 2010 @ 19:53

    i have need in one account and multiple sign

  • NURUL HUDA Jan 9, 2011 @ 16:04

    I have lost my all inbox mails unexpectedly.Is it possible to retrive again?please help me.

  • emiat Feb 1, 2011 @ 4:52

    what is the 1st step on how to add group in active directory 2003? And 1st step of how to add group in active directory?


  • Rodislav Moldovan Apr 3, 2011 @ 22:01

    #works in Debian 6
    Add user to a new group, by keeping old groups
    usermod -a -G AdditionalGroup User

    -a append
    -G group name

  • Rashid May 12, 2011 @ 10:50

    thanks for sharing useful and knowledgeable topic

  • Extra Jun 27, 2011 @ 8:02

    Oh yeah man! This is the best site i ever meet, on helping users to quick find the answer to concrete Question! Thank you so much for the FAQ archive! wish you the best thinks.
    this is the primary site, that i search for responses to Linux Q’s.

  • Laxman Rana Sep 20, 2011 @ 4:37

    thanks this tutorial to learn about user add with group’s modification…
    nicely this iz working on my pc in linux……………

  • Neth Kong Oct 8, 2011 @ 16:16

    Hi all, I would like to write a script in Linux to manage User and Group….
    *** they are able to add, delete, modify,,,,,,

    Would you please help me?

  • da_fatfinger Oct 20, 2011 @ 22:48

    I made the mistake of not including -a in usermod as well, now im locked of doing anything useful in ubuntu. Granted i’m a linux newbie, so hard lessons like this are bound to happen, but you would save many headaches with just a small, clear explanation at the top about how flags (especially -a) are vital to how usermod works. Since you are THE top google hit for “linux add user to group”, you would save a lot of people some serious pain.

  • Vivek Nov 9, 2011 @ 14:04

    Any idea howto add existing group into another existing group ?

    Ex: test1 – group has 5 users
    test2 – group has 3 users

    i want to add test1 group to be part of test2, instead of adding the users.

  • vlad the impaler Dec 8, 2011 @ 12:43

    Can you please emboss, move to top, highlight, make it red and blink FFS !!!
    99 % of the people want an user added to an existing group, not moved.
    Only on Linux, add is a special type of move (sarcasm).

    Please, for this tutorial of yours, that comes up on google, this is what we want:
    usermod -a -G ftp tony
    not this:
    usermod -G ftp tony

    Maybe with time we will learn Linux and face this issues more bravely, but most of us that come here have rather trivial experience with Linux, we want to learn.. but we want to learn how to add an user to a group (of course existing, is the natural way) no how to damage our systems.

    Call me stupid, but it is the 2nd time I revisit this issue, being forced to again reinstall my linux box because of damaging my sudoers list.

    Please, put a big red or whatever flashy warning on top of the article, notifying people about the sudeoers bite.

  • miquel Jan 12, 2012 @ 8:11

    Nice explanation

  • diptesh maity Feb 22, 2012 @ 15:02

    how to create user under user in linux?? not from superuser.

    • Subrat N Jan 10, 2013 @ 18:03

      You should know the root password.

      $su – -c “useradd u_name”

      or through sudo

  • marc Mar 26, 2012 @ 8:22

    I knew that useradd could add a user to the system but I did not know that it would for a group as well. Thanks for this how-to then.

  • remove this Apr 10, 2012 @ 15:28

    This post is wrong and it’s the top search result on google. You should edit or remove it.

    The correct way to add a user to a group is “usermod -aG groupname username”.

  • nitiratna nikalje Apr 25, 2012 @ 13:19

    its mind blowing solution for adding user to any group .we can add multiple existing users to an existing group by this method # gpasswd -M niti,gauri,lina,nidhi masti =added user niti ,gauri ,lina and nidhi to group “masti”

  • Jeremy Jun 11, 2012 @ 17:03

    Thanks, this is helpful for people like myself; just starting out with RHEL.

  • dhani Sep 18, 2012 @ 8:21

    Thank you, this really solve my problems in samba share.

  • Bijay Manandhar Sep 20, 2012 @ 6:24

    really nice tutorial ..

    thanx millions..

  • Valerio Oct 15, 2012 @ 18:41

    Hi… I tryed your hint, but I have got some erros below:
    root@ibeji:/etc# testparm
    Load smb config files from /etc/samba/smb.conf
    Unknown parameter encountered: “client code page”
    Ignoring unknown parameter “client code page”
    Unknown parameter encountered: “character set”
    Ignoring unknown parameter “character set”
    Unknown parameter encountered: “domain admin group”
    Ignoring unknown parameter “domain admin group”
    Unknown parameter encountered: “domain admin users”
    Ignoring unknown parameter “domain admin users”
    Processing section “[netlogon]”
    Processing section “[home]”
    Processing section “[publico]”
    Processing section “[contabil]”
    Processing section “[suporte]”
    Processing section “[tmp]”
    Loaded services file OK.
    Server role: ROLE_DOMAIN_PDC
    Press enter to see a dump of your service definitions

  • Sequoia Dec 18, 2012 @ 17:05

    You should really change this article to either
    a) use the -a switch in the first example or
    b) add a BIG RED WARNING that the command you give will REMOVE THE USER FROM ALL CURRENT GROUPS

    This comes up #1 on google for “linux add user to group” and I suspect I’m not the only one who completely screwed up their user by running the command you have listed here to “add a user to a group”

    Perhaps the article should be titled “How to remove a user from all groups and add them to a new group”

  • Subrat N Jan 10, 2013 @ 17:52

    Hi Geeks,

    How can I add multiple users into a group at a time without removing the old users belongs to that particular group.
    I have tried the following command

    #gpasswd -M user1,user2,user3 group_name

    But, the thing is that, after adding these users, the previous users belongs to this group being removed.
    I want the previous users to be exist.
    Please, help……..
    Thanks in advance …..

  • Luis Mompo Handen Jan 22, 2013 @ 13:35

    I built a bash script to add multiple users from a csv-file to an existing group without creating a home dir. The passwords in csv-file are clear text.

    cat $FILE | while read line; do
       USER=$(echo $line | awk -F\; '{print $1}')
       PASS_TMP=$(echo $line | awk -F\; '{print $2}' | sed 's/\ //g')
       useradd -M -G cvs_usr $USER
       echo $USER:$PASS_TMP | chpasswd
  • Landis Jan 27, 2013 @ 19:30

    In SuSE linux, there is No -a (this article states that the ‘-a’ retains existing groups and ‘adds’ new group ‘-G’), but in openSuSE 12.2 at least, there is no ‘-a’ option to usermod, it keeps existing groups, by default i guess…
    # usermod -G GroupName UserName
    # id lunar
    uid=1002(lunar) gid=100(users) groups=100(users)
    # usermod -G sshd lunar
    # id lunar
    uid=1002(lunar) gid=100(users) groups=100(users),102(sshd)

  • Vaibhav Gupta Jan 31, 2013 @ 15:09

    Hi ,
    I have built a x86 rootfs using buildroot with both ifuse , imobiledevice ,usbmuxd . i did chroot ( directory :/var/prj_ca/) to the generated filesystem and mounted the following
    mount –bind /dev /var/prj_ca/dev
    mount –bind /dev/pts /var/prj_ca/dev/pts
    mount –bind /dev/fuse /var/prj_ca/dev/fuse
    mount –bind /proc /var/prj_ca/proc
    mount –bind /sys /var/prj_ca/sys
    mount –bind /media /var/prj_ca/media
    when i run .
    lsusb -v | grep -i iSerial i am getting the IPOD serial id but .
    ifuse is failing with following error.
    ifuse /tmp/apple_inc._ipod_b067d003ed1b22a9fffa47e3654a00e6386a6c9a/
    usbmuxd_get_device_list: error opening socket!
    No device found, is it connected?
    If it is make sure that your user has permissions to access the raw usb device.
    If you’re still having issues try unplugging the device and reconnecting it.

    I am stuck can u please help.

  • Muhammad Usman Majeed Apr 22, 2013 @ 7:46

    # usermod -a -G ftp tony

    what did the ‘-a’ switch do?


  • prashanth Jul 12, 2013 @ 12:35

    is there any way to add multiple users to a existing group with disturbing or deleting existing users in that group

  • George Huebschman Jul 16, 2013 @ 17:49

    A very clear thorough answer to the question!

    “When you have a choice, spend your money where you’d prefer to work if you had NO choice.”

  • bb Nov 7, 2013 @ 13:52

    adduser not useradd

  • Jose Dec 31, 2013 @ 22:24

    Excellent bro !, I’m using fedora and this is very usefull for HTTPD directories !

  • Golandaj S Feb 5, 2014 @ 6:45

    adduser account

    • Golandaj Saddam Feb 5, 2014 @ 6:47


  • Naveen Sharma Apr 25, 2014 @ 12:45

    I got this question lately in an interview.
    One User ID can belong to maximum how many secondary groups.?

    Is there a definite no?

  • JET Apr 25, 2014 @ 23:45

    The format of this post took out an important part of the commands. PLEASE DISREGARD ABOVE. Here is an ammended post:

    A simple “man usermod” will provide the options available. The -A option does not remove any groups, it only adds. For adding a user to a group, MY preferred method is:
    usermod username -A group

    If you wish to add user to a list of groups, you may use a comma as delimiter, as in:
    usermod username -A group1,group2,group3

    The -G option is not preferred in my opinion, it is used to specify all groups to which the user will belong to, and has the ability to REMOVE a user from unspecified groups. As many have pointed out, the ability to remove a user from groups can have nasty results if not carefully used.

    So, just use the -A option to add your existing users to existing groups, and you should be all set. Good luck!

    • Extra Dec 18, 2014 @ 10:51

      Good point Jet! Thank You!

  • raja May 19, 2014 @ 2:45

    i am create the create to the roup bdba an user add but he was not add to the usermod command.
    usermod -u 1000 -g dba -d |d01|oracle

  • lliseil Jan 1, 2015 @ 17:26

    # Post’s original command (does not work):

    useradd -G GROUP USER
    useradd: user 'USER' already exists

    # Working command:

    gpasswd -a USER GROUP
    Adding user USER to group GROUP

    # Help:

    gpasswd -h
    Usage: gpasswd [option] GROUP
      -a, --add USER                add USER to GROUP
      -d, --delete USER             remove USER from GROUP[/code]

    Arch linux here.

  • pandiyan Jan 3, 2015 @ 12:10

    thanks friends…..

  • Craig R Morton Jan 13, 2015 @ 15:33

    Excellent, thank you.

  • Harry Hinson likes erica Feb 23, 2015 @ 12:00

    complete noob with linux here…

    what are the actual groups that you can add users to?

    i know there’s the ‘users’ group for standard users… but what else is there? can i add a user as a sysadmin with full control over the system? or is that the same as logging in as root?

    i also understand it’s apperently a “bad idea” to login as root into KDE… but why?

    sorry, like i said, complete noob. just installed yesterday.

    oh, and also, even though i realize this isn’t the right place to ask this, i have no idea where else to ask and i’ve been seraching for this for hours… how do you mount a new hard drive? there’s plenty of info telling how to mount a cdrom or a floppy drive, or even a usb thumb drive, but NOWHERE does anything or anyone say how to mount a simple hard drive…. is it not possible to add an additional hard drive? i can’t believe that that would be impossible, so there’s got to be a way.

    • harry hindson Feb 24, 2015 @ 14:25

      I promise I do fancy her no joke

  • pradeep Jul 16, 2015 @ 3:34

    Good command explanations

  • Nina Jul 16, 2015 @ 13:18

    Hi, I want to know how to create a group in redhad but to be sure that this group is created in the local machine and not in the grid where I am connected at. I saw man and found option groupadd -r that seesm to add the user to the system account. How could I be sure that the new group is created in the local system? Thanks

  • Reddy Aug 19, 2015 @ 15:55

    This just saved my day. Thank you.

  • angiekarix Sep 29, 2015 @ 5:11

    I wanted to know how I can add multiple users at once and not necessarily in one group.

  • ROhit Feb 18, 2016 @ 17:56

    hi All

    How to create Group in Centos 6.7
    Group name “Project Manager”

    what is the cli commands
    Please share asap.

  • Vasanth Muthu Feb 25, 2016 @ 21:40

    Fantastic!!! Your blog is full of information. I finally added a user to a group in linux….. Thanks,

  • Peter Mar 29, 2016 @ 20:06

    Great thank you, tired of looking on google every time lol hitting back to school this summer!

  • Poldovico Oct 25, 2016 @ 21:04

    Does “usermod -G group” remove me from every other group? If so, the guide should mention.
    Because in doing “usermod -G my_username www-data”) I seem to have removed myself from the sudo group on my remote server on which the root account is locked. Which is fun.

    • 🐧 Vivek Gite Oct 26, 2016 @ 19:23

      Why you skipped the -a option while using usermod command? The guide clearly use the example as follows:
      usermod -a -G ftp tony

      • Poldovico Oct 27, 2016 @ 10:37

        So I did. Crap.
        My apologies.
        At least I was able to fix my mistake without needing a reinstall or getting support involved, so I got that going for me.

  • Kevin Feb 4, 2017 @ 7:04

    Hi Please help me this assignment
    Q: Assign permission to access folder /share only member of IT, Sale, and Finance

    Please answer!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum