Oct 16, 2023 3 min read

How to Delete Group on Linux (groupdel Command)

Delete Group on Linux (groupdel Command) with our step-by-step tutorial. The groupdel command is used on Linux to delete a group from the system.

Delete Group on Linux (groupdel Command)
Table of Contents

Introduction

Before we begin talking about how to delete group on Linux (groupdel Command), let's briefly understand – What is groupdel command ?

The groupdel command is used on Linux to delete a group from the system. To utilize this command, you would typically need administrative privileges or be logged in as the root user.

Groups are used on Linux to organize and manage user accounts. The fundamental goal of groups is to define a set of privileges for a certain resource that may be shared across the users inside the group, such as reading, writing, or executing permission.

In this tutorial, groupdel command is used to remove a group on Linux. We will also address a few FAQs on how to delete group on Linux (groupdel command).

Advantages of  groupdel command

  1. Deletes groups: groupdel allows removing groups from a Linux system, helping to manage user access and permissions efficiently.
  2. Administrative control: With the appropriate privileges, it provides administrators the ability to control and maintain the group structure of the system.
  3. Streamlines user management: Deleting obsolete or unused groups helps to simplify user management, improving security and organization in the process.
  4. Safeguards system resources: Removing unnecessary groups reduces the risk of unauthorized access or misuse of system resources.
  5. Cleanup and organization: groupdel aids in the cleanup and organization of group-related files and configurations, promoting a more organized system environment.

groupdel Command Syntax

The groupdel command has the following general syntax:

groupdel [OPTIONS] GROUPNAME

The name of the group you want to eliminate is GROUPNAME.

Groups can only be removed by root or a user with sudo access.

It is not feasible to remove an existing user's primary group without first removing the user.

Only a few infrequently used options are accepted by the groupdel command. For additional details on the command's options, see the groupdel man page.

Deleting a Group on Linux

Invoke the groupdel command followed by the group name to remove a specified group from the system.

To remove a group named mygroup, for example, type:

sudo groupdel mygroup

The group item in the /etc/group and /etc/gshadow files are removed with the command above.

The groupdel command does not print any output when it succeeds.

You may confirm that the group has been removed by running the following command to list all groups:

sudo getent group | grep mygroup

If the group you seek to eliminate does not exist, the system will not output anything.

FAQs to Delete Group on Linux (groupdel Command)

What happens to the files owned by the group being deleted? 

By default, the files owned by the group are not affected. If you want to remove these files as well, you can use the -r option with the groupdel command.

Can I delete the "sudo" group using groupdel? 

It is generally not recommended to delete the "sudo" group, as it provides administrative privileges. Removing it may lead to a loss of important system access.

How can I delete a group forcefully, even if users are still assigned to it? 

You can use the -f option with groupdel to force the deletion of a group even if users are currently assigned to it.

Can I delete multiple groups using a single groupdel command? 

No, the groupdel command can only delete one group at a time. You need to specify the name of the group you want to delete.

Can I undo the deletion of a group using groupdel? 

No, once a group is deleted with groupdel, it cannot be easily restored. It is recommended to have a backup or take precautions before using the command.

Are there any dependencies or considerations before using groupdel? 

Yes, you should ensure that no users are currently logged into the group you want to delete and that no system processes rely on it.

Does the groupdel command require root or administrative privileges?

Yes, typically you need to have root or administrative privileges to use the groupdel command, as it involves managing system-wide groups.

Conclusion

The groupdel command on Linux can be used to remove groups.

Any Linux distribution, including Ubuntu, CentOS, RHEL, Debian, Fedora, and Arch Linux, can use these instructions.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.