LinuxCommandLibrary

adduser

Add a new user account

TLDR

Create a new user with a default home directory and prompt the user to set a password

$ adduser [username]
copy

Create a new user without a home directory
$ adduser --no-create-home [username]
copy

Create a new user with a home directory at the specified path
$ adduser --home [path/to/home] [username]
copy

Create a new user with the specified shell set as the login shell
$ adduser --shell [path/to/shell] [username]
copy

Create a new user belonging to the specified group
$ adduser --ingroup [group] [username]
copy

SYNOPSIS

adduser [options] username [group]
adduser username group
adduser --system username
adduser --help

PARAMETERS

--home DIR
    Specify the user's home directory.

--shell SHELL
    Specify the user's login shell.

--uid ID
    Specify the user's unique ID (UID).

--gid ID
    Specify the primary group ID (GID).

--ingroup GROUP
    Specify the primary group by name.

--disabled-password
    Do not set a password, user cannot login until one is set.

--disabled-login
    Do not allow login until password is set.

--force-badname
    Allow usernames that do not conform to system regex.

--system
    Create a system account (UIDs typically below 1000).

--no-create-home
    Do not create the user's home directory.

--add_extra_groups
    Add user to common extra groups defined in config.

--debug
    Enable verbose debug output.

--help
    Display a help message and exit.

DESCRIPTION

The adduser command is a high-level utility used to add new user accounts to a Linux system. It provides a more user-friendly and often interactive interface compared to the lower-level useradd command. While useradd directly manipulates system configuration files such as /etc/passwd, /etc/shadow, and /etc/group, adduser automates several steps. These include creating the user's home directory, copying default skeleton files from /etc/skel, setting up initial permissions, and prompting the administrator for necessary user details like username, password, and full name.

The specific implementation and features of adduser can vary significantly between Linux distributions. For instance, on Debian and Ubuntu systems, adduser is a sophisticated Perl script that handles many complexities automatically, while on Red Hat and CentOS, useradd is typically the preferred and more commonly used tool for both manual and automated user creation tasks. This command ensures that all necessary configurations for a new user are set up correctly and consistently.

CAVEATS

The behavior and available options of adduser can differ significantly between Linux distributions. It is primarily a feature-rich script on Debian/Ubuntu systems, whereas on Red Hat/CentOS, useradd is the more direct and commonly used utility.

Execution typically requires root privileges.

Its interactive nature, while user-friendly for manual operations, makes it less ideal for shell scripting and automation, where useradd is generally preferred due to its non-interactive nature.

INTERACTIVE PROMPTS

On Debian/Ubuntu systems, adduser is highly interactive. It prompts the administrator for a new password and then for optional 'full name', 'room number', 'work phone', 'home phone', and 'other' information. This interactive process ensures all relevant user details can be captured during creation.

CONFIGURATION FILE

The default behavior of adduser is controlled by the /etc/adduser.conf configuration file (on Debian/Ubuntu systems). This file allows administrators to customize various aspects of new user accounts, such as the default home directory, default shell, private user group settings, UIDs/GIDs ranges, and password expiration policies.

HISTORY

The adduser command emerged as a more administrator-friendly alternative to the lower-level useradd utility, especially prominent in Debian-based distributions. While useradd directly manipulates core system files like /etc/passwd and /etc/shadow, adduser automates a broader range of tasks. This includes creating home directories, copying skeleton files from /etc/skel, setting up default group memberships, and prompting for additional user information. Its design philosophy was to simplify user creation and ensure consistency. In contrast, Red Hat-based systems have historically relied more heavily on useradd for both interactive and scripted user account management.

SEE ALSO

useradd(8), usermod(8), userdel(8), passwd(1), groupadd(8), groupdel(8), groups(1), chown(1)

Copied to clipboard