Deleting user groups

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

Delete an user group using the groupdel command

  1. To delete a group, execute:

    $ sudo groupdel groupToDelete
  2. 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
  3. Check that the group has been removed:

    $ grep '^groupToDelete' /etc/group

Delete an user group using the delgroup command

  1. To delete a group, execute:

    $ sudo delgroup groupToDelete
  2. Check that the group has been removed:

    $ grep '^groupToDelete' /etc/group
  3. 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
  4. If you want to backup the files before removing an user group, use the --backup option:

    $ sudo delgroup --backup --group groupToDelete

Remove an user from a group

Use the following command to remove an user from a group:

$ sudo deluser userToRemove groupName

Other articles:

How to list all users in Linux - part 1

How to create users in Linux

How to delete users in Linux

How to create user groups in Linux