GroupAdd and GroupMod commands

G

Groupadd command – adding groups to Linux

The groupadd command provides the ability to add a new group to Linux. It is similar to useradd, but has fewer options. The basic syntax of the groupadd command is:

groupadd [-g GID [-o]] [-r] [-f] [-K] group_name

The parameters used by this command have the following meanings:

GID specification

We can specify a specific GroupIDentifier (GID) using the -g GID parameter. If this parameter is omitted, groupadd uses the following available GID. This value will be within the range specified by the GID_MIN and GID_MAX values stored in the /etc/login.defs file.

Along with this parameter, you can also use -o, which allows you to create a group with a non-unique GID.

-K overrides the default (GID_MIN, GID_MAX) values in the /etc/login.defs file; example: -K GID_MIN=58 -K GID_MAX=267

Create a System Group

To create a system group (which has a GID between SYS_GID_MIN and SYS_GID_MAX, values that are defined and stored in the /etc/login.defs file), we will use the -r parameter. Groups that have GIDs within this range are considered system groups, similar to system accounts.

System groups are used by system utilities or to control system resources.

Forcing the creation of a group

Normally, if we want to create a group that already exists, the groupadd command will return an error message. The -f parameter suppresses this message – not all distributions support this parameter.

Most of the time, we will create a new group without specifying any parameters:

#groupadd music

The above command will create the Music group that will have the GID provided by the system – as a rule, the largest existing GID plus 1. After we place this order, we can start adding users. If we create new users, they can be added to the group directly through the useradd command options.

To remember:

• certain features of the groups are defined in the /etc/login.defs file: GID_MAX (number), GID_MIN (number), MAX_MEMBERS_PER_GROUP (number), SYS_GID_MAX (number), SYS_GID_MIN
• the names of the defined groups must not exceed 32 characters; Also, the name of a group must start with a small letter or a underscore (_).

GroupMod command – modifying group properties in Linux

The groupmod command changes the properties of an existing group. Its syntax has the following form:

groupmod [-g GID [-o]] [-n new_group_name] old_group_name

Specification of a new GID

Specifying a new Group Identifier can be done with the -g GID option. An error will be returned if a new Group ID is already in use. To use a value that is not unique, the -g option is used with -o.

Groups renaming

There is the possibility to specify a new name for an existing group; this is possible with the -n new_group_name parameter.

About the author

Ilias spiros
By Ilias spiros

Recent Posts

Archives

Categories