useradd vs adduser: Key Differences and When to Use Each in Linux System Administration


15 views

In Linux system administration, both useradd and adduser serve the purpose of creating new user accounts, but they approach this task differently.


# Basic useradd command
sudo useradd newusername

# Basic adduser command
sudo adduser newusername

useradd is a low-level utility that comes as part of the shadow-utils package. It's the barebones command that simply creates an entry in system files without any additional configuration.

adduser, on the other hand, is a Perl script that acts as a friendly front-end to useradd. It provides an interactive experience and handles many configuration aspects automatically.

  • Interactive vs Non-interactive: adduser prompts for information while useradd requires all parameters in the command
  • Default configurations: adduser sets up home directories and copies skeleton files automatically
  • Password handling: adduser prompts for password while useradd leaves the account locked

Use useradd when:


# Creating a system user without home directory
sudo useradd -r -s /usr/sbin/nologin serviceuser

# Scripting user creation with specific parameters
sudo useradd -m -d /home/customdir -s /bin/bash -G developers newdev

Use adduser when:


# Quickly creating regular user accounts interactively
sudo adduser john

# When you want the system to handle defaults appropriately
sudo adduser --ingroup developers sarah

For more complex scenarios, you might combine both commands:


# First create user with specific parameters
sudo useradd -m -d /opt/specialuser -s /bin/zsh specialuser

# Then use adduser to configure additional aspects
sudo adduser specialuser audio
sudo adduser specialuser video

Since implementations vary across distributions, it's good to check:


# Check if adduser is a symlink
ls -l $(which adduser)

# View the actual script (on Debian-based systems)
less $(which adduser)

The useradd command is a low-level utility present on all Linux distributions as part of the shadow-utils package. In contrast, adduser is a Perl script wrapper that exists primarily in Debian-based systems (Ubuntu, Mint, etc.), providing more user-friendly interactive features.

# useradd example (basic usage)
sudo useradd -m -s /bin/bash newuser

# adduser example (interactive)
sudo adduser newuser

useradd performs minimal actions by default - it creates an entry in /etc/passwd without creating a home directory or setting up defaults unless explicitly told to. adduser on the other hand:

  • Creates home directory by default
  • Sets up basic configuration files
  • Prompts for additional information (full name, phone, etc.)
  • Can set up encrypted home directories

useradd reads defaults from /etc/default/useradd, while adduser uses /etc/adduser.conf. Here's how to examine defaults:

# View useradd defaults
useradd -D

# View adduser configuration
cat /etc/adduser.conf

Use useradd when:

  • Writing scripts or automated processes
  • Needing fine-grained control over user creation
  • Working across different Linux distributions

Use adduser when:

  • Interactively creating users on Debian systems
  • Wanting the convenience of built-in prompts
  • Needing standard configurations applied automatically

Creating a user with specific UID/GID and expiration date:

# Using useradd
sudo useradd -u 1501 -g developers -e 2024-12-31 -c "Temporary contractor" tempuser

# Equivalent with adduser requires manual steps:
sudo adduser --uid 1501 --gid 1001 tempuser
sudo chage -E 2024-12-31 tempuser

Creating system users (no home directory):

# useradd approach
sudo useradd -r -s /usr/sbin/nologin serviceaccount

# adduser equivalent
sudo adduser --system --no-create-home --group serviceaccount