What's the command line utility and the arguments it requires?


9 Answers 9


The utility is usermod and is used like:

usermod -a -G group1,group2 username

Where username is the user you want to modify and group1 and group2 are the new groups you want that user to join. Running the command without the -a argument will remove that user from all groups except group1 and group2.

To check a users group memberships use the groups command:

groups username
usermod -a -G group1,group2,group3 username

Assuming the user already exists, the easiest way is to just open the file /etc/group and add the username to the relevant groups that you want them to be a member of. The usernames are comma separated from the other usernames in the group.

You can check by doing a id -G username to verify if they are members of the groups you intended.


On Debian, and I assume on Ubuntu as well, the canonical way of adding users and adding users to groups is through the adduser script, not useradd. To add a user to a group, just use:

adduser user group

Though using useradd or usermod works as well of course and is probably more cross platform (but the adduser script reads settings from /etc/adduser.conf and is hence usually preferable).

  • 3
    "How do I add a user to multiple groups in Ubuntu?"
    – Gauthier
    Feb 13, 2015 at 10:06
  • @Gauthier run the above twice, once for each group. I figured that was obvious.
    – wds
    Feb 16, 2015 at 10:19
  • 1
    Obviously you can run a command to add a user to a single group twice, but given the way the question is phrased I would expect any answer to explain how to add a user to two groups using a single command once.
    – Ariel
    Mar 25, 2021 at 8:03
usermod -a -G groupname username

Use usermod with the -a and -G options.


Adding Groups

groupadd group1
groupadd group2

Adding user to the group

useradd -G group1,group2 -d /home/user1 -s /usr/bin/bash user1

id user1 

will show the details of user user1


Another way of doing this is by copying the group membership of one user to another user like this:

for i in `grep -E "(:|,)<username>(:,|$)" /etc/group|cut -f1 -d:` ; do
  addgroup <newuser> $i

Source: Stev.Org | Linux - List / Copy group membership for users


First, as an infosec professional I completely agree with the additional security benefits and best practices SUDO provides.
However, the self-proclaimed experts who repeatedly belch forth the tired "I-know-how-but-I'm-not-going-to-tell-you-so-go-learn-SUDO-&-sudoers" mantra are the same individuals who post explicit command-line configurations for complex OS & service installations or modifications INCLUDING THE SUDO command, without considering that newbies are simply copying & pasting these commands into their installations without understanding ANY of the risks or the increased attack surface the changes may be creating. Such behavior creates MORE security issues than sharing the information to allow a user to create alternate root accounts.

**Before using the following commands, it is your responsibility to understand the ramifications of creating and using a root-level account. Use may result in a security compromised system or you may render your system COMPLETELY UNUSABLE.

** You agree by using the information contained herein that any negative impact or results to any system, data or network are entirely your responsibility.

Create additional root-level accounts by running these commands from a terminal session:

sudo su

useradd -G root <newusername>

passwd <newusername>

id <newusername>

You should see something similar to: uid=1001(newusername) gid=1001(newusername groups=0(root).

usermod -o -u 0 -g 0 <username>

(in the usermod command string, the first switch is the letter "O". The characters following the -u and -g switches are each "zero")

id <username>

You should now see something similar to: uid=0(root) gid=0(root) groups=0(root).

I suggest bouncing your system prior to logging on with the newly created root-level user account.

shutdown -r now

These commands work well in most main stream *nix and BSD distributions. Use them wisely.

  • This is completely unrelated to the question asked. Mar 3, 2022 at 15:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .