adduser

user managementlinux
The adduser command is one of the most frequently used commands in Linux/Unix-like operating systems. adduser The adduser command creates a new user account on the system with a home directory and other default settings. It is a higher-level, more user-friendly alternative to the lower-level useradd command.

Quick Reference

Command Name:

adduser

Category:

user management

Platform:

linux

Basic Usage:

adduser [options] [arguments]

Common Use Cases

  • 1

    User account creation

    Create new user accounts with proper home directories and settings

  • 2

    System administration

    Add users to the system with appropriate permissions and groups

  • 3

    Multi-user setup

    Set up user accounts for shared systems or servers

  • 4

    Service account creation

    Create dedicated accounts for running specific services

Syntax

adduser [options] [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID] [--firstuid ID] [--lastuid ID] [--gecos GECOS] [--ingroup GROUP | --gid ID] [--disabled-password] [--disabled-login] [--encrypt-home] [--add_extra_groups] [--quiet] user

Options

Option Description
--home DIR Use DIR as the user's home directory instead of the default
--shell SHELL Use SHELL as the user's login shell instead of the default
--no-create-home Do not create the user's home directory
--uid ID Use ID as the user ID instead of automatic selection
--firstuid ID Use ID as the smallest UID when automatically selecting
--lastuid ID Use ID as the largest UID when automatically selecting
--gecos GECOS Set the GECOS field (full name, etc) for the new user
--ingroup GROUP Add the user to GROUP instead of creating a new group
--gid ID Use ID as the group ID for the user's primary group
--disabled-password Set no password on the account
--disabled-login Create the account but disable login
--encrypt-home Encrypt the user's home directory
--system Create a system user (lower UID, no home directory expiry)
--add_extra_groups Add new user to extra groups defined in configuration
--quiet Suppress informational messages, only show warnings and errors
--debug Be verbose when processing and show debugging information
--conf FILE Use FILE instead of the default configuration file
--help Display help information and exit
--version Output version information and exit

Examples

How to Use These Examples

The examples below show common ways to use the adduser command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

Basic Examples:

Create a new user with default settings
adduser johndoe
Create a new system user
adduser --system sysuser
Add an existing user to a group
adduser johndoe sudo
Create a user with a specific home directory
adduser --home /custom/home/dir janedoe
Create a user with a specific shell
adduser --shell /bin/zsh johndoe

Advanced Examples:

Create a user with a specific UID and GID
adduser --uid 1500 --gid 1000 johndoe
Create a user without a home directory
adduser --no-create-home tempuser
Create a user with a disabled password
adduser --disabled-password serviceaccount
Create a user with custom GECOS information
adduser --gecos "John Doe,Room 123,555-1234,555-5678," johndoe
Create a user and add them to multiple groups
adduser --add_extra_groups johndoe

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Adduser vs Useradd:

The adduser command is a Debian/Ubuntu-specific script that provides a more user-friendly interface to the lower-level useradd command. Key differences include:

  • adduser interactively prompts for user information like password and user details
  • adduser automatically creates a home directory and copies files from /etc/skel
  • adduser sets up appropriate permissions for the home directory
  • adduser creates a group with the same name as the user by default
  • adduser is more distribution-specific, while useradd is available on all Linux distributions

GECOS Field:

The GECOS field is a comma-separated list of user information with the following format:

Full Name,Room Number,Work Phone,Home Phone,Other

You can set this information using the --gecos option. For example:

--gecos "John Doe,Room 123,555-1234,555-5678,"

Adding Users to Groups:

The adduser command can be used in two ways:

  1. To create a new user: adduser username
  2. To add an existing user to a group: adduser username groupname

Configuration:

The adduser command is configured through the /etc/adduser.conf file, which defines default settings such as:

  • Default home directory location (DHOME)
  • UID and GID ranges (FIRST_UID, LAST_UID, FIRST_GID, LAST_GID)
  • Default shell (DSHELL)
  • Default groups to add new users to (EXTRA_GROUPS)
  • Directory structure to copy to new home directories (/etc/skel)

System Users:

When creating system users with --system:

  • The UID will be chosen from below 1000 (typically)
  • No home directory is created by default
  • The account is set up without password expiry
  • No user interaction is required

Important Notes:

  • The adduser command requires root privileges (sudo)
  • User names must begin with a lowercase letter or underscore, followed by lowercase letters, digits, underscores, or dashes
  • User names may not exceed 32 characters in length
  • By default, adduser creates a primary group with the same name as the user
  • The --add_extra_groups option adds the user to additional groups defined in /etc/adduser.conf (often includes groups like audio, video, etc.)
  • Home directories are typically created under /home/username unless specified otherwise

Common Use Cases

User account creation

Create new user accounts with proper home directories and settings

System administration

Add users to the system with appropriate permissions and groups

Multi-user setup

Set up user accounts for shared systems or servers

Service account creation

Create dedicated accounts for running specific services

User provisioning

Automate user account creation in large environments

Related Commands

These commands are frequently used alongside adduser or serve similar purposes:

Use Cases

1

User account creation

Create new user accounts with proper home directories and settings

2

System administration

Add users to the system with appropriate permissions and groups

3

Multi-user setup

Set up user accounts for shared systems or servers

4

Service account creation

Create dedicated accounts for running specific services

5

User provisioning

Automate user account creation in large environments

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the adduser command works in different scenarios.

$ adduser
View All Commands