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!! 🙂
One thought on “The groupadd command’s switches with example – Unix/Linux”