The groupadd command’s switches with example – Unix/Linux

The “gropadd” is used to create a new group under Linux.
Syntax:

# groupadd [options] GROUPNAME

Switches with example:

1, -f, –force
This option causes the command to simply exit with success status if the specified group already exists. When used with -g, and the specified GID already exists, another (unique) GID is chosen (i.e. -g is turned off).

2, -g, –gid GID

The numerical value of the group´s ID. This value must be unique, unless the -o option is used. The value must be non-negative. The default is to use the smallest ID value greater than 999 and greater than every other group. Values between 0 and 999 are typically reserved for system accounts.
Example:

[root@localhost ~]# groupadd -g 666 megrp 
[root@localhost ~]# grep -w megrp /etc/group
megrp:x:666:

3, -h, –help
Display help message and exit.

4, -K, –key KEY=VALUE
Overrides /etc/login.defs defaults (GID_MIN, GID_MAX and others). Multiple -K options can be specified.
Example: -K GID_MIN=100 -K GID_MAX=499
Note: -K GID_MIN=10,GID_MAX=499 doesn´t work yet.

5, -o, –non-unique

This option permits to add a group with a non-unique GID.
Example:

[root@localhost ~]# groupadd -o -g 666 megrp2 
[root@localhost ~]# grep megrp /etc/group
megrp:x:666:
megrp2:x:666:

6, -p, –password PASSWORD

The encrypted password, as returned by crypt(3). The default is to disable the password.
Note: This option is not recommended because the password (or encrypted password) will be visible by users listing the processes. You should make sure the password respects the system´s password policy.

7, -r, –system

Create a system group.
The numeric identifiers of new system groups are choosen in the SYS_GID_MIN-SYS_GID_MAX range, defined in login.defs, instead of GID_MIN-GID_MAX.

That’s it!! 🙂

Also refer:
groupdel, groupmems, groupmod,

More
ls, head, tail, top, ps, find, crontab

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

One thought on “The groupadd command’s switches with example – Unix/Linux

Leave a Reply

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