Mastering the groupadd Command on Linux

The “groupadd” command is a tool for system administrators to create and manage groups on Linux systems such as Ubuntu, an open-source operating system. Its syntax comprises options and flags that modify its behavior, with functions like creating a new group, assigning a group ID, changing the password, etc. This command-line utility provides beginners a…

The groupadd command is used by system administrators to add or create groups on Ubuntu Linux and other Linux systems. It is an essential tool for managing user and group accounts on a Linux system.

Groupadd creates new groups, modifies existing groups, and sets group permissions for files and directories. Using the groupadd command, you can specify the group ID (GID) for a new group, which determines the group’s numerical identification on the system.

Overall, the groupadd command is an essential tool for managing user and group accounts on a Linux system, and it is particularly useful for system administrators who need to manage large numbers of users and groups.

About groupadd command:

The groupadd command is used by system administrators to add/create groups on Linux systems. In addition, it can perform essential group management on Ubuntu and other Linux platforms.

Like using your mouse and keyboard to add groups or manage settings in the GUI., the groupadd is how to do it on the command line.

Syntax:

The syntax is the rule and format of how the groupadd command can be used. The syntax options can be reordered. But a straight format must be followed.,.

Below is an example syntax of how to use the groupadd command.

groupadd [options] GROUP

Options:

The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the command. They are separated by spaces and followed after the command options.

Below are some options for the groupadd command:

    GROUPUse the -f or –force option to exit with a success message if the group already exists. When used with the -g option and the group exists, a new GID is created
-f, –force
Use the -g or –gid GID for your new group.
-g, –gid GIDUse the -o or –non-unique option to allow the use of a duplicate (non-unique) GID
-o, –non-uniqueUse the -R or –root CHROOT_DIR option set the directory to chroot into
-p, –password PASSWORDUse the -P or –password PASSWORD option to change the password to this (encrypted) PASSWORD.
-R, –root CHROOT_DIRUse the -R or –root CHROOT_DIR option sets the directory to chroot into
-h, –helpdisplay this help message and exit

Examples:

Below are some examples of how to run and use the groupadd on Ubuntu Linux.

To create a new group named members, you run the commands below.

groupadd members

You run the commands below if you wish to create a members group with a GID of 8080. by default, if you don’t specify a GID for a group, Linux automatically assigns one.

groupadd -g 8080 members

If you’re not logged in as a root account, you may have to use the sudo command.

sudo groupadd -g 8080 members

Assigning the automatic group id uses the GID_MIN and GID_MAX values specified in the /etc/login. defs config file. f you want to set your values, you can specify that using the -K option, as shown below

sudo groupadd -K GID_MIN=8080 -K GID_MAX=8090 members

In the example above, the groupadd command created the account with group id 8081, between the values 8000 – 9999 we specified in the command line.

When you run groupadd with the –help option, you’ll see the help text below:

Usage: groupadd [options] GROUP

Options:
  -f, --force                   exit successfully if the group already exists,
                                and cancel -g if the GID is already used
  -g, --gid GID                 use GID for the new group
  -h, --help                    display this help message and exit
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -o, --non-unique              allow to create groups with duplicate
                                (non-unique) GID
  -p, --password PASSWORD       use this encrypted password for the new group
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into
      --extrausers              Use the extra users database

That’s it!

I hope you like it, and please come back soon for more Ubuntu Linux commands!

Comments

Leave a Reply

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