How to Create Users with useradd vs adduser on Linux
In this tutorial, you'll learn about How to Create Users with useradd vs adduser on Linux. We cover key concepts, practical examples, and best practices.
The Problem
You need to create a new Linux user but are unsure whether to use useradd or adduser. Running the wrong command leaves you without a home directory, no shell, or a confusing error.
Quick Fix
Use adduser for Interactive User Creation
sudo adduser jane
# Adding user `jane' ...
# Adding new group `jane' (1001) ...
# Adding new user `jane' (1001) with group `jane' (1001) ...
# Creating home directory `/home/jane' ...
# Copying files from `/etc/skel' ...
# Enter new UNIX password:
# Retype new UNIX password:
# passwd: password updated successfully
adduser (Perl script on Debian/Ubuntu) is interactive: it creates the home directory, copies skeleton files, prompts for a password, and asks for optional GECOS info.
Use useradd for Non-Interactive / Scripted Creation
sudo useradd -m -s /bin/bash -G sudo john
sudo passwd john
# New password:
# Retype new password:
# passwd: password updated successfully
useradd is the low-level binary. Use -m to create a home directory, -s to set the login shell, and -G to add supplementary groups. Always set a password with passwd afterward.
Create a System User with No Login Shell
sudo useradd --system --no-create-home --shell /usr/sbin/nologin appservice
# (no output)
grep appservice /etc/passwd
# appservice:x:998:998::/home/appservice:/usr/sbin/nologin
Use --system for service accounts, --no-create-home to skip the home directory, and --shell /usr/sbin/nologin to prevent login.
Delete a User and Clean Up
sudo userdel -r jane
# userdel: jane mail spool (/var/mail/jane) not found
userdel -r removes the user and deletes their home directory and mail spool. Without -r, the home directory remains.
Create Batch Users from a File
# users.txt format: username:password:uid:gid:gecos
while IFS=: read -r user pass uid gid gecos; do
sudo useradd -m -u "$uid" -g "$gid" -c "$gecos" "$user"
echo "$user:$pass" | sudo chpasswd
done < users.txt
For bulk user creation, use useradd in a loop driven by a data file. This is much faster than creating users interactively with adduser one at a time.
Use Debug Mode for Risky Operations
# See every command before it executes
bash -x risky_script.sh
# + sudo sed -i 's/old/new/' /etc/fstab
Always use debug mode when running scripts that modify system configuration like fstab, SELinux settings, or firewall rules. This shows every command before it executes, catching typos early.
Additional Troubleshooting
# Check the error message and stack trace for more context
echo "Review the full error output to identify the root cause"
If the above steps do not resolve the issue, examine the complete error message and stack trace. Often the key detail is in the middle of the traceback rather than the final line. Search for the error message in the project documentation or issue tracker for additional solutions.
Prevention
- Use
adduserfor interactive, manual user creation on Debian-based systems - Use
useraddin scripts for predictable, repeatable user creation - Always specify
-m(create home) and-s(shell) withuseraddfor human users - Use
--system --no-create-homefor application service accounts
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro