FUNDAMENTALS A Complete Guide for Beginners
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.
Process flow chart to remove user from a group using “gpasswd” Command:
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
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”. To do so, follow the steps:
- Launch an Ubuntu Terminal by pressing CTRL+ALT+T.
- Insert the following command:
groups walid
This shows the groups that the user “walid” joined. Also, there is a group “mygroup” and I will remove the user from that group.EXPLANATION- groups: Allows to view and manage groups.
- walid: Name of the user.
Step 02: Remove the User from a Group Using “gpasswd” in Linux
In this step, I will use the gpasswd
to remove the user “walid” from group “mygroup”. Check the steps below:
- Copy the command below on the Ubuntu Terminal:
Command Syntax >
sudo gpasswd -d USERNAME GROUPNAME
sudo gpasswd -d walid mygroup
EXPLANATION- 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 of user walid from group mygroup was successful. Follow the steps to verify it:
- Write the following command on the terminal:
groups walid
EXPLANATION- 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
How to remove a user from a group using “gpasswd” command?
To remove a user from a group using gpasswd
command, write the following code in your terminal:
sudo gpasswd -d walid mygroup
This command will delete the user “walid” from the group called “mygroup”.
What is gpasswd in Linux?
The gpasswd is a command that is used to administer groups in Linux. It writes group information in /etc/gshadow and /etc/group files. Using this command, an administrator can define group administrators and members.
How can I delete my group members?
There are multiple ways to delete a user from a group. However, the best approach is using the gpasswd
command with option -d
like: sudo gpasswd -d USERNAME GROUPNAME
.
How to remove a password from a group in Linux?
You can use the gpasswd
to remove passwords from a group. To do that, you need to use the option -r
. For instance, if you have a group named “mygroup”, you can use the following command to remove the password from that group:
sudo gpasswd -r mygroup
How do you delete a group in Linux?
To delete a group in Linux, you need to use the groupdel command. You need to provide the group name as well. For example, if I want to delete a group named “mygroup”, I will use the following command:
sudo groupdel mygroup
Related Articles