On Unix-like operating systems, the adduser command creates a new user, and the addgroup command creates a new group.

The adduser command can also be used to add an existing user to an existing group.

How to use adduser and addgroup

adduser and addgroup add users and groups to the system according to command line options and configuration information in /etc/adduser.conf. They are friendlier front ends to the low-level tools like useradd, groupadd and usermod programs, by choosing policy-conformant UID and GID values, creating a home directory with skeletal configuration, running a custom script, and other features.

  • How to use adduser and addgroup

  • Add a normal user

  • Add a system user

  • Add a user group

  • Add a system group

  • Add an existing user to an existing group

  • Syntax

  • Exit values

  • Files

  • Examples

  • Related commands

  • Linux command list

  • Add a normal user

  • Add a system user

  • Add a user group

  • Add a system group

  • Add an existing user to an existing group

There are five major ways to use adduser and addgroup can run in one of five modes:

Add a normal user

If called with one non-option argument and without the –system or –group options, adduser adds a normal user.

adduser chooses the first available UID from the range specified for normal users in the configuration file. The UID can b overridden with the –uid option.

The range specified in the configuration file may be overridden with the –firstuid and –lastuid options.

By default, each user in a GNU/Linux system is given a corresponding group with the same name. User groups allow group writable directories to be easily maintained by placing the appropriate users in the new group, setting the set-group-ID bit in the directory, and ensuring that all users use a umask of 002. If this option is turned off by setting USERGROUPS to no, all users’ GIDs are set to USERS_GID. Users’ primary groups can also be overridden from the command line with the –gid or –ingroup options to set the group by id or name, respectively. Also, users can be added to one or more groups defined in adduser.conf either by setting ADD_EXTRA_GROUPS to 1 in adduser.conf, or by passing –add_extra_groups on the command line.

adduser creates a home directory subject to DHOME, GROUPHOMES, and LETTERHOMES. The home directory can be overridden from the command line with the –home option, and the shell with the –shell option. The home directory’s set-group-ID bit is set if USERGROUPS is yes so that any files created in the user’s home directory have the correct group.

adduser will copy files from SKEL into the home directory and prompt for finger (gecos) information and a password. The gecos may also be set with the –gecos option. With the –disabled-login option, the account is created but will be disabled until a password is set. The –disabled-password option will not set a password, but login is still possible (for example with SSH RSA keys). To set up an encrypted home directory for the new user, add the –encrypt-home option.

If the file /usr/local/sbin/adduser.local exists, it will be executed after the user account is set up to do any local setup. The arguments passed to adduser.local are: “username uid gid home-directory”.

The environment variable VERBOSE is set according to the following rules:

  • if –quiet is specified
  • if neither –quiet nor –debug is specified
  • if –debug is specified

(The same applies to the variable DEBUG, but DEBUG is deprecated and will be removed in a later version of adduser).

Add a system user

If called with one non-option argument and the –system option, adduser adds a system user. If a user with the same name already exists in the system uid range (or, if the uid is specified, if a user with that uid already exists), adduser will exit with a warning. This warning can be suppressed by adding “–quiet”.

adduser chooses the first available UID from the range specified for system users in the configuration file (FIRST_SYSTEM_UID and LAST_SYSTEM_UID). If you want to have a specific UID, you can specify it using the –uid option.

By default, system users are placed in the “nogroup” group. To place the new system user in an already existing group, use the –gid or –ingroup options. To place the new system user in a new group with the same ID, use the –group option.

A home directory is created by the same rules as for normal users. The new system user has the shell /bin/false (unless overridden with the –shell option), and have logins disabled. Skeletal configuration files are not copied.

Add a user group

If adduser is called with the –group option and without the –system option, or addgroup is called, a user group is added.

A GID will be chosen from the range specified for system GIDS in the configuration file (FIRST_GID, LAST_GID). To override that mechanism, you can give the GID using the –gid option.

The group is created with no users.

Add a system group

If addgroup is called with the –system option, a system group is added.

A GID will be chosen from the range specified for system GIDS in the configuration file (FIRST_SYSTEM_GID, LAST_SYSTEM_GID). To override that mechanism, you can give the GID using the –gid option.

Add an existing user to an existing group

If you run adduser with two non-option arguments, it adds existing user user to group group, if it 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] user group

Options

Configuration

The file /etc/adduser.conf contains defaults for the programs adduser, addgroup, deluser and delgroup. Each line holds a single value pair in the form “option = value”. Double or single quotes are allowed around the value, as is whitespace around the equals sign. Comment lines must have a hash sign ("#") in the first column.

The valid configuration options are:

Exit values

Files

Examples

adduser mynewuser

Creates a new user account, mynewuser.

adduser prompts you to assign a password for the user, and ask you for optional identifying information such as Full Name and Phone Number.

A home directory (by default, /home/mynewuser) is created for the new user, and a user-specific group, mynewuser, is created. The contents of the skeleton home directory, which by default is located at /etc/skel, is copied into the new home directory.

If the script /usr/local/sbin/adduser.local exists, it will be executed with the arguments username uid gid home-directory, where username is mynewuser, uid is mynewuser’s user id, gid is mynewuser’s group id, and home-directory is mynewuser’s home directory.

adduser –home /home/mynewuserhome mynewuser

Creates the user account mynewuser, and creates their home directory at the location /home/mynewuserhome.

deluser — Remove a user from the system.finger — List information about a user.groupadd — Add a group to the system.passwd — Change a user’s password.useradd — Add a user to the system.userdel — Remove a user from the system.usermod — Modify a user’s account.