How to delete group in linux

How to delete group in linux

NAME

deluser, delgroup - remove a user or group from the system

SYNOPSIS

deluser [options] [--force] [--remove-home] [--remove-all-files] [--backup] [--backup-to DIR] user deluser --group [options] group delgroup [options] [--only-if-empty] group deluser [options] user group COMMON OPTIONS [--quiet] [--system] [--help] [--version] [--conf FILE]

DESCRIPTION

deluser and delgroup remove users and groups from the system according to command line options and configuration information in /etc/deluser.conf and /etc/adduser.conf. They are friendlier front ends to the userdel and groupdel programs, removing the home directory as option or even all files on the system owned by the user to be removed, running a custom script, and other features. deluser and delgroup can be run in one of three modes: Remove a normal user If called with one non-option argument and without the --group option, deluser will remove a normal user. By default, deluser will remove the user without removing the home directory, the mail spool or any other files on the system owned by the user. Removing the home directory and mail spool can be achieved using the --remove-home option. The --remove-all-files option removes all files on the system owned by the user. Note that if you activate both options --remove-home will have no effect because all files including the home directory and mail spool are already covered by the --remove-all-files option. If you want to backup all files before deleting them you can activate the --backup option which will create a file username.tar(.gz|.bz2) in the directory specified by the --backup-to option (defaulting to the current working directory). Both the remove and backup options can also be activated for default in the configuration file /etc/deluser.conf. See deluser.conf(5) for details. If you want to remove the root account (uid 0), then use the --force parameter; this may prevent to remove the root user by accident. If the file /usr/local/sbin/deluser.local exists, it will be executed after the user account has been removed in order to do any local cleanup. The arguments passed to deluser.local are: username uid gid home-directory Remove a group If deluser is called with the --group option, or delgroup is called, a group will be removed. Warning: The primary group of an existing user cannot be removed. If the option --only-if-empty is given, the group won't be removed if it has any members left. Remove a user from a specific group If called with two non-option arguments, deluser will remove a user from a specific group.

OPTIONS

--conf FILE Use FILE instead of the default files /etc/deluser.conf and /etc/adduser.conf --group Remove a group. This is the default action if the program is invoked as delgroup. --help Display brief instructions. --quiet Suppress progress messages. --system Only delete if user/group is a system user/group. This avoids accidentally deleting non-system users/groups. Additionally, if the user does not exist, no error value is returned. This option is mainly for use in Debian package maintainer scripts. --backup Backup all files contained in the userhome and the mailspool-file to a file named /$user.tar.bz2 or /$user.tar.gz. --backup-to Place the backup files not in / but in the directory specified by this parameter. This implicitly sets --backup also. --remove-home Remove the home directory of the user and its mailspool. If --backup is specified, the files are deleted after having performed the backup. --remove-all-files Remove all files from the system owned by this user. Note: --remove-home does not have an effect any more. If --backup is specified, the files are deleted after having performed the backup. --version Display version and copyright information.

RETURN VALUE

0 The action was successfully executed. 1 The user to delete was not a system account. No action was performed. 2 There is no such user. No action was performed. 3 There is no such group. No action was performed. 4 Internal error. No action was performed. 5 The group to delete is not empty. No action was performed. 6 The user does not belong to the specified group. No action was performed. 7 You cannot remove a user from its primary group. No action was performed. 8 The required perl-package 'perl modules' is not installed. This package is required to perform the requested actions. No action was performed. 9 For removing the root account the parameter "--force" is required. No action was performed.

FILES

SEE ALSO

deluser.conf(5), adduser(8), userdel(8), groupdel(8)
Copyright (C) 2000 Roland Bauerschmidt. Modifications (C) 2004 Marc Haber and Joerg Hoh. This manpage and the deluser program are based on adduser which is: Copyright (C) 1997, 1998, 1999 Guy Maor. Copyright (C) 1995 Ted Hajek, with a great deal borrowed from the original Debian adduser Copyright (C) 1994 Ian Murdock. deluser is free software; see the GNU General Public Licence version 2 or later for copying conditions. There is no warranty.

© 2019 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.

Читайте также:  Arch linux kde plasma install

Источник

Delete Groups in Linux With groupdel Command

Learn how to delete a group in Linux using groupdel command. Also learn what to do with files owned by the deleted groups.

In an earlier article, I discussed the groupadd command which is used for adding new groups to your Linux system.

In this article, I’ll discuss another group management command which is groupdel. It is used for deleting groups from your system.

Using groupdel command in Linux

The groupdel command is perhaps the simplest command in Linux with virtually no options (other than one for chroot).

All you have to do is to specify the group name. The group must exist, of course.

Did you notice that I used sudo with the groupdel command? It’s because it is an administrative command and you need to be root or sudo user to run this command.

How do you get the group name? You can list groups for a user or manually check all the groups present in your system by viewing the content of file /etc/group.

Groupdel Command

Keep in mind: You cannot delete primary group of a user without deleting the user

If you try to remove the primary group of an existing user, you should see an error like this:

groupdel: cannot remove the primary group of user ‘abhishek’

This is by design. You cannot delete the primary group of an existing user. You have two options here:

  • Change the primary group of a user using usermod command
  • Delete the user using userdel command and then delete the group
Читайте также:  Linux get timezone offset

Keep in mind: Files belonging to the deleted group will not change group ownership

The groupdel command doesn’t change the group ownership of any files. It simply removes the group name from the system. If you list files owned by a deleted group, you’ll see the group id (GID) instead of group name.

I hope you are aware of the file permission and ownership concept in Linux. As you can see below, the file belongs to group tesla:

[email protected]:~$ ls -l a.txt -rw-r--r-- 1 abhishek tesla 57 Feb 24 15:57 a.txt

Once I delete the group, the file shows the group ID (998 in the example) instead of the group name:

[email protected]:~$ sudo groupdel tesla [email protected]:~$ ls -l new.txt -rw-r--r-- 1 abhishek 998 1717 Feb 24 15:58 new.txt

What do you do with such files, then? It’s up to you really. You can leave it like that or use a combination of find, xargs and chgrp command to change the group of files belonging to the GID of the deleted group like this:

find . -gid 998 | xargs chgrp another_group_name

Since we are speaking of file permissions and ownership, you might want to know about the stat command that can display these information in detail.

I hope this tutorial gave you a better understanding of the groupdel command in Linux. If you have any questions or suggestions, please let me know in the comments.

Источник

How to Delete Groups with groupdel Command in Linux

The “groupdel” command in Linux removes the account from Linux. It provides a way for administrators to remove a group and its associated permissions, making it no longer accessible for users or processes.

Using this command, we can manage and delete users that we no longer need. Here we will create a group of users and then delete it using the groupdel command.

How to Delete Groups with groupdel Command in Linux

To list all the groups run below-mentioned command:

Here we can see group1 displayed which we just created.

How to Delete a Group Using groupdel Command

Now to delete a specific group we will use the below-given command. For example, to delete the group1 from list run the groupdel command:

Once the group is deleting again, list all groups to confirm the deletion. Now again run the /etc/group command:

Here we can see the group1 is successfully removed using the groupdel command.

For example, if a certain group doesn’t delete, the “-f” flag will forcefully delete this group. To delete group1 using the “-f” flag, run the below command:

The grep command can also confirm whether a certain group is deleted or not.

If no output is displayed on the terminal, it means the group is already deleted.

Читайте также:  Astra linux sudo add apt repository

For more info about groupdel run the given command:

Conclusion

The Linux “groupdel” command is a powerful tool for managing group accounts on a Linux system. It enables administrators to remove groups that are no longer needed, ensuring the security and efficiency of the system by reducing the number of unneeded access controls.

About the author

Kashif

I am an Electrical Engineer. I love to write about electronics. I am passionate about writing and sharing new ideas related to emerging technologies in the field of electronics.

Источник

How to create, delete, and modify groups in Linux

Groups are an essential part of the Linux permission structure and a powerful way to manage file access on your system.

Hands pointing at a laptop screen while another person uses the mouse

In Linux, groups are collections of users. Creating and managing groups is one of the simplest ways to deal with multiple users simultaneously, especially when dealing with permissions. The /etc/group file stores group information and is the default configuration file.

[ Keep your most commonly used commands handy with the Linux commands cheat sheet. ]

Linux admins use groups to assign access to files and other resources. Every group has a unique ID listed in the /etc/group file, along with the group name and members. The first groups listed in this file are system groups because the distribution maintainers preconfigure them for system activities.

Each user may belong to one primary group and any number of secondary groups. When you create a user on Linux using the useradd command, a group with the same name as the username is also created, and the user is added as the group’s sole member. This group is the user’s primary group.

Training & certification

Create and modify groups

To add a group in Linux, use the groupadd command:

When a group is created, a unique group ID gets assigned to that group. You can verify that the group appears (and see its group ID) by looking in the /etc/group file.

If you want to create a group with a specific group ID (GID), use the —gid or -g option:

$ sudo groupadd -g 1009 demo1

If group ID 1009 is already allocated to another group, you’re alerted that the GID is unavailable and the operation aborts. Rerun it with a different group ID number:

$ sudo groupadd -g 1010 demo1

Change the group ID

You can change the group ID of any group with the groupmod command and the —gid or -g option:

$ sudo groupmod -g 1011 demo1

Great Linux resources

Rename a group

You can rename a group using groupmod with the —new-name or -n option:

$ sudo groupmod -n test demo1

Verify all these changes from the /etc/group file.

Add and remove users from a group

Suppose you have existing users named user1 and user2, and you want to add them to the demo group. Use the usermod command with the —append —groups options ( -a and -G for short):

$ sudo usermod --append --groups demo user1 $ sudo usermod -aG demo user2

Look in the /etc/group file or use the id command to confirm your changes:

$ id user1 uid=1005(user1) gid=1005(user1) groups=100(users),1009(demo)

To remove a specific user from a group, you can use the gpasswd command to modify group information:

$ sudo gpasswd --delete user1 demo

Alternatively, manually edit the /etc/group file and remove the user from any number of groups.

Источник

Оцените статью
Adblock
detector