How to create and delete groups in Linux with groupadd and groupdel

Groups are important in Linux systems. In order to have a well secured distro, you will need to set security rules on both users and groups. The information about the groups is stored in /etc/group.

How to create groups in Linux with: groupadd

$ sudo groupadd mikegr
$ < /etc/group grep mikegr
mikegr:x:1022:

With groupadd and no arguments, a new group will be with the default setting. The GID will be the first one available, bigger than 1000 (because from 1 to 999 the GIDs are reserved).

You can also create a group with a customized GID:

$ sudo groupadd -g 1033 starwarsmovie
$ < /etc/group grep starwarsmovie starwarsmovie:x:1033:

It is not recommended to create a password protected group with groupadd -p because you're password will be stored in /etc/gshadow in clear format, not encrypted. (unless you give groupadd -p a crypted password as an argument)

$ sudo groupadd -p "linuxg.net" geekster
$ < /etc/group grep geekster geekster:x:1035: $ sudo < /etc/gshadow grep geekster geekster:linuxg.net::

Deleting a group is very simple with groupdel:

$ sudo groupdel geekster

We did not get any output, so the group has been succesfully deleted.
If you need to change the group settings, use groupmod:

$ groupmod
Usage: groupmod [options] GROUP

Options:
-g, --gid GID change the group ID to GID
-h, --help display this help message and exit
-n, --new-name NEW_GROUP change the name to NEW_GROUP
-o, --non-unique allow to use a duplicate (non-unique) GID
-p, --password PASSWORD change the password to this (encrypted)
PASSWORD

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!