In Linux, groups are a way to control access and share resources where different groups enjoy different privileges. An administrator can remove a user from a group for different reasons as changing job responsibilities, security concerns etc. The gpasswd command is a powerful tool to add or remove a user and manage group passwords. In this article, I will show you how to remove a user from a group using the gpasswd command in Ubuntu.
Key Takeaways
- Viewing the groups of a user.
- Removing a user from a group.
Requirements
- You need to have sudo/root privileges to remove a user from a group.
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
Watch how to Remove a User from a Group using the ‘gpasswd’ Command
3 Steps to Remove a User from a Group using the gpasswd Command
In my Ubuntu, there is a user by the name of “walid” and he is in a group named “mygroup”. Now I will remove user “walid” from the “mygroup” group using the gpasswd by the following three steps.
Step 01: View Current Groups in Ubuntu
In the beginning, I will check the current groups of the user “walid”.
Steps to Follow >
➊ Launch an Ubuntu Terminal by pressing CTRL+ALT+T.
➋ Insert the following command:
groups walid
- groups: Allows to view and manage groups.
- walid: Name of the user.
Step 02: Remove the User from a Group in Linux
In this step, I will use the gpasswd to remove the user “walid” from group “mygroup”.
Steps to Follow >
❶ Copy the command below on the Ubuntu Terminal:
Command Syntax >
sudo gpasswd -d USERNAME GROUPNAME
sudo gpasswd -d walid mygroup
- sudo: Grants root privileges.
- passwd: Adds or removes users and manages group passwords.
- -d: Deletes user.
- walid: Name of the user.
- mygroup: Name of the group.
❷ Provide the password (if necessary).
❸ Press the ENTER button from the keyboard.In the output, you should see something like “Removing user walid from group mygroup”.
- How to Delete User Account In Ubuntu? [2 Methods]
- Delete a User from an Ubuntu Server in Just 3 Steps
- How to Delete User and All Files in Ubuntu [3 Methods]
Step 03: Check if the User is Removed Successfully in Linux
Finally, I will check if removing user “walid” from group “mygroup” was successful.
Steps to Follow >
➊ Write the following command on the terminal:
groups walid
- groups: Allows to view and manage groups.
- walid: Name of the user.
➋ Hit the ENTER key from the keyboard.If you look carefully, you will see there is no group by the name of “mygroup” here. So I have successfully removed user “walid” from group “mygroup”.
Conclusion
In this article, I have tried to show you how to remove a user from a group in Ubuntu in a simple and comprehensive way. I hope you find my effort helpful.
People Also Ask
Related Articles