Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

migrated from stackoverflow.com Jan 14 '10 at 22:40

This question came from our site for professional and enthusiast programmers.

9 Answers 9

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
done

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

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
usermod -a -G groupname username
share|improve this answer
usermod -a -G group1,group2,group3 username
share|improve this answer

Use usermod with the -a and -G options.

share|improve this answer
up vote 53 down vote accepted

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
share|improve this answer

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

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.