addgroup Command in Linux with Examples

What is the addgroup command?

It is a command in Linux to create a new group using specified command lined and the system’s default values.

How to add groups

  • Adding a user group: If we want to add a user group, we either call adduser with the –group option without using the –system option, or we call addgroup.
  • Adding a system group: To add a system group, we call addgroup with the –system option. Here also, the group created will have no users.
  • Adding an existing user to a group that already exists: If the adduser is run with two non-option arguments, then the user is added to a group if it already exists.

Syntax:

adduser [--system] [--home DIR] [--shell SHELL] [--no-create-home]
        [--uid ID] [--firstuid ID] [--lastuid ID]
        [--ingroup GROUP | --gid ID] [--disabled-password]
        [--disabled-login] [--gecos GECOS] [--add_extra_groups]
        [--encrypt-home] [--quiet] [--debug] [--force-badname]
        [--help|-h] [--version] [--conf FILE] user


addgroup [--system] [--quiet] [--debug] [--force-badname] [--help|-h]
         [--version] [--conf FILE] [--gid ID] group
adduser [options] usergroup

 Some options used in the above line code are explained here:

--conf FILE    This option use FILE in place of /etc/adduser/conf.
--disabled-loginThis option makes the user set a password for his account, or else he would not be able to use his account.
--disabled    password     This option is similar to –disabled-login, but the user can log in to his account without using a password.
--force-badnameThe user and group names are checked, by default. So, this option pressures adduser and addgroup to check roughly for the cogency of the name.
--gecos GECOSThis option will restrict the adduser to ask for finger information.
--gid IDWhen this option is used, the given number is forced to bethe new group ID. If a user is created/added, due to this option he is added to that group.
--group         If we want to create the group with the same name as the system user, we combine this option with the --system. If this option is not combined with the --system, then the group with the given name is created.
--helpThis option is used to show a help message and exit.
--home DIR  If we use DIR as the user’s home directory, then if the directory does not exist, it is created and the skeleton files are copied.
--quiet           This option only displays errors and warnings and hides informational messages.
--systemThis option creates a system group or system user.
--add_extra_groupsThis option adds a new user to extra groups.
--versionThis option shows copyright information and version.

Configuration

The file /etc/adduser.conf holds defaults for the programs. Every line contains a single value pair in the form “option = value”. A hash sign (#) is compulsory in a comment line.

Some of the valid configuration options are:

DSHELLThis is the log-in shell that is used for all users. Reverts to /bin/bash.
DHOMEThis is the directory where the new home directories have to be created. Reverts to /home.
GROUPHOMESThe home directory is created as “/home/[groupname]/user” if set to yes. Reverts to no.
SKEL   This is the directory from which the user configuration files have to be copied. Reverts to /etc/skel.
LETTERHOMESThe home directories have an extra directory added that is the first letter of the login name if this is set to yes.

Files

/etc/adduser.confIt is a revert layout for adduser and addgroup.

Working on addgroup command in Linux

  • For adding a new group
sudo addgroup groupname
addgroup Command in Linux with Examples

This command creates a new group for our Linux Machine.

  • For adding a new group with a specified Group ID (GID)
sudo addgroup groupname --gid 12345
addgroup Command in Linux with Examples

This command adds a new group with a specified Group ID (GID).

  • For creating a group with a specific shell
sudo addgroup groupname --shell /bin/sh
addgroup Command in Linux with Examples

The /bin/sh shell is allocated to the newly created group with the help of this command.

  • For entering verbose mode
sudo addgroup groupname --debug
addgroup Command in Linux with Examples

All the commands will be executed in the verbose mode i.e., all the details of the operations being performed will be printed, when this command is used.

  • ToFor show help related to the addgroup command
addgroup –help
addgroup Command in Linux with Examples

The help section of the addgroup command can be displayed using this command.

  • For displaying version
addgroup –version
addgroup Command in Linux with Examples

To show version details of the addgroup command, the version command is used.