Linux How to Add Users to Groups

How to Add Users to Groups in LinuxOk, I know there are man pages, I know there are hundreds of posts on the internet explaining linux user groups, and I know there are posts everywhere explaining how to add users to groups in Linux. However, every single time I need a quick reference, I just can’t seem to find a good clean one. I see forums, I see a bunch of competing information, more than anything I see noise.

So, that’s why I’m writing my own post on how to add users to groups in Linux. We’ll be using the user tommy in these examples:

 

New Users useradd

# Add user to supplementary group
$ useradd -G groupname tommy

# Add user to multiple groups
$ useradd -G groupname,groupname2 tommy

# Add user to primary group
$ useradd -g groupname tommy

Existing Users usermod

# Add user to supplementary groups
$ usermod -a -G groupname tommy

# Assign new primary group to user
$ usermod -g groupname tommy

Show Groups id

# Check the user group membership
# Shows tommy is member of groupname (primary), and group2 (supplementary)
$ id tommy
uid=500(tommy) gid=500(tommy) groups=500(groupname),400(groupname2)

# Bonus: Remove tommy from groupname2
$ gpasswd -d tommy groupname2

Now, this is lifted verbatim from the post here:

This is another post I’ve used:

Here’s some other simple writeups:

I’m trying to give attribution here, but I just want to get this mirrored for my own use, because over the years I’ve seen good sites and good information just vanish.

So, to wrap this up. These are my instructions for adding users to groups in Linux.

Post written by Ed Reckers

Founder and lead web development consultant at Red Bridge Internet : San Francisco WordPress Developers and Consultants.

Leave a Reply