In this article I will walk through the steps of how to add and remove users from groups in Linux, we have already covered how to add multiple users in Linux.
Being able to administrate the users on a Linux system is important from both a security point of view and performance, and part of the every day job of a Linux admin. Lets look at how we can manage groups in Linux in the following steps.
Step 1: Adding Users to Linux Groups
To add a user to a group in Linux you need to use the
usermod command with the two flags
-aG. The first instructs
usermod to add the user to the supplementary groups, while the second names the groups to use.
The following will add the user
bob to the group
usermod -aG writer bob
We can check the groups a user belongs to with the following command to check adding the user was successful.
Note, if you have multiple users to add to a group you can repeat this process for each user.
Step 2: Removing Users from Linux Groups
Now we know how to add users to groups lets go ahead and remove users, the reverse process. To remove users from a group in Linux we need to use the
gpasswd command and the
-d flag as follows.
gpasswd -d bob writer
Note that the ordering of the group name and user is reversed compared to before. We can check if it was successful as before with the
Note that on Ubuntu it is also fine to use the
deluser command instead of
This article has discussed and shown the two ways to add and remove users from groups in Linux, if you need more information consult the man pages for the two commands.