When you have a user group that you no longer need, you might want to delete that user group. There are several ways to do that in Linux. Here, I will show you two of them, which are almost similar: using groupdel
and delgroup
commands
groupdel
commandTo delete a group, execute:
$ sudo groupdel groupToDelete
You can remove the primary group of a user by passing the -f
option to the groupdel
command. For example, you can remove the admins group:
$ sudo groupdel -f admins
Check that the group has been removed:
$ grep '^groupToDelete' /etc/group
delgroup
commandTo delete a group, execute:
$ sudo delgroup groupToDelete
Check that the group has been removed:
$ grep '^groupToDelete' /etc/group
Another option is to delete an user group only if it is a system user group. This will help you to avoid accidentally deleting non-system user groups. To do that, you must use the --system
option:
$ sudo delgroup --system --group groupToDelete
If you want to backup the files before removing an user group, use the --backup
option:
$ sudo delgroup --backup --group groupToDelete
Use the following command to remove an user from a group:
$ sudo deluser userToRemove groupName