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-login | This 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-badname | The 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 GECOS | This option will restrict the adduser to ask for finger information. |
--gid ID | When 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. |
--help | This 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. |
--system | This option creates a system group or system user. |
--add_extra_groups | This option adds a new user to extra groups. |
--version | This 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:
DSHELL | This is the log-in shell that is used for all users. Reverts to /bin/bash. |
DHOME | This is the directory where the new home directories have to be created. Reverts to /home. |
GROUPHOMES | The 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. |
LETTERHOMES | The 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.conf | It is a revert layout for adduser and addgroup. |
Working on addgroup command in Linux
- For adding a new group
sudo addgroup groupname
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
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
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
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
The help section of the addgroup command can be displayed using this command.
- For displaying version
addgroup –version
To show version details of the addgroup command, the version command is used.