02. Creating and Modifying Groups

Creating a Group

To create a group, use the groupadd command.

$ groupadd family
-g
Specify group id (else, system will make one for you).
-f
Force create a group, even if it already exists.
-n
Change name of the group.
-o
Allow duplicate groupnames to be created.
-r
Create a system group ID (gid < 500).

Notice that there's an option to set the group ID to less than 500 with the -r option. All group ID's in this range are known a system processes and not real user-populated groups. You may check all current groups within the /etc/group file, which we'll go over in detail shortly.

Modifying a Group

To modify a group, use the groupmod command. Let's try renaming our family group to cousins.

$ groupmod -n cousins family

Deleting groups

To delete a group, simply use the groupdel command.

$ groupdel cousins

Here's some extra practice for using the above commands and options.

$ groupadd developers
# Check to see that the new group has been added
$ cat /etc/group
# Let's say we have a group with GID 1010 already
$ groupadd -g 1010 developers
# This should error out. Now let's allow duplicates
$ groupmod -o -g 1040 developers
# Rename 
$ groupmod -n cool-kids developers

Take your Linux skills to the next level!

Linux for Beginners

Take your Linux skills to the next level! Try Linux & UNIX

Linux for Beginners doesn't make any assumptions about your background or knowledge of Linux. You need no prior knowledge to benefit from this book. You will be guided step by step using a logical and systematic approach. As new concepts, commands, or jargon are encountered they are explained in plain language, making it easy for anyone to understand.

$ Check price
24.9924.99Amazon 4.5 logo(101+ reviews)

More Linux & UNIX resources

Want to avoid becoming a code monkey?

Code Complete 2

Want to avoid becoming a code monkey? Try Good Practice

This book synthesizes the most effective techniques and must-know principles into clear, pragmatic guidance. No matter what your experience level, development environment, or project size, this book will inform and stimulate your thinking - and help you build the highest quality code.

$ Check price
54.9954.99Amazon 4.5 logo(291+ reviews)

More Good Practice resources

Ad