To add a user in Linux, run sudo adduser username (on Ubuntu/Debian) which creates the account interactively with a home directory and password prompt, or sudo useradd -m username followed by sudo passwd username for a more manual approach. To remove a user, run sudo deluser username (Ubuntu/Debian) or sudo userdel username, adding -r or --remove-home to also delete their home directory. All user management commands require root privileges via sudo.
Multi-User Linux
Linux is fundamentally a multi-user operating system. Even on a personal desktop used by one person, Linux maintains a structured user account system — your personal account, system service accounts, and the root superuser all coexist within the same framework. On shared servers, workstations used by multiple people, or development environments with multiple developers, understanding how to manage user accounts is an essential administrative skill.
User management in Linux involves more than just creating and deleting accounts. It encompasses setting and changing passwords, managing home directories, controlling which groups a user belongs to, modifying account properties, temporarily disabling accounts, and understanding the files that store all this information. Getting user management right directly affects both security (who can access what) and usability (whether users can log in and use the system effectively).
This article covers the full lifecycle of user management on Linux: creating new accounts with the right properties, setting and managing passwords, modifying existing accounts, adding users to groups, disabling accounts without deleting them, and cleanly removing accounts and their data when no longer needed. Both the Ubuntu/Debian style (adduser/deluser) and the lower-level POSIX-compliant tools (useradd/userdel) are covered, with clear explanations of when to use each.
How Linux Stores User Information
Before creating or managing users, understanding where Linux stores user data provides essential context for everything that follows.
/etc/passwd: The User Database
Every user account on a Linux system has an entry in /etc/passwd. Despite its name, this file no longer stores passwords — it stores user account information. It is world-readable (any user can read it), which is necessary because many programs need to look up user information:
$ cat /etc/passwd | grep sarah
sarah:x:1000:1000:Sarah Johnson,,,:/home/sarah:/bin/bash
Each line has seven colon-separated fields:
username : password : UID : GID : GECOS : home_directory : shell
sarah : x : 1000: 1000: Sarah Johnson,,, : /home/sarah : /bin/bash
- username — the login name (
sarah) - password —
xmeans the actual password hash is in/etc/shadow(the secure password file) - UID — User ID number (1000 for the first regular user on most distributions)
- GID — Primary Group ID (1000, which typically matches the user’s personal group)
- GECOS — Comment field with full name and other info (optional, often multiple comma-separated subfields)
- home_directory — where the user’s files live (
/home/sarah) - shell — the default shell for this user (
/bin/bash)
/etc/shadow: The Password Database
Actual password hashes are stored in /etc/shadow, which is readable only by root. This separation means that even though user names and UIDs are public, password hashes are protected:
$ sudo cat /etc/shadow | grep sarah
sarah:$6$randomsalt$hashedpassword...:19774:0:99999:7:::
The shadow file fields include the hashed password, when the password was last changed, minimum and maximum password age, warning period, and account expiration information.
/etc/group: The Group Database
Group memberships are stored in /etc/group:
$ cat /etc/group | grep sarah
sarah:x:1000:
sudo:x:27:sarah
developers:x:1001:sarah,bob,carol
Each line shows: group name, password (usually x), GID, and comma-separated list of members.
User Home Directories
Each regular user has a home directory, conventionally at /home/username. When a user logs in, their shell starts in their home directory. Their personal files, configuration files (dotfiles like .bashrc and .config/), and application data live here.
The template for new home directories comes from /etc/skel — a skeleton directory whose contents are copied into every new user’s home directory at creation time.
Adding Users: Two Approaches
Linux provides two command-line tools for creating user accounts. Understanding the difference helps you choose the right one.
adduser: The Friendly Interactive Tool (Ubuntu/Debian)
adduser is a higher-level Perl script included in Debian-based distributions. It walks you through user creation interactively, making sensible decisions automatically:
$ sudo adduser sarah
Adding user `sarah' ...
Adding new group `sarah' (1001) ...
Adding new user `sarah' (1001) with group `sarah' ...
Creating home directory `/home/sarah' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for sarah
Enter the new value, or press ENTER for the default
Full Name []: Sarah Johnson
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
adduser automatically:
- Creates the user account with the next available UID
- Creates a personal group with the same name
- Creates the home directory at
/home/sarah - Copies skeleton files from
/etc/skelinto the home directory - Sets correct permissions on the home directory
- Prompts for a password immediately
- Prompts for optional GECOS information (full name, etc.)
For most Ubuntu/Debian user creation tasks, adduser is the right tool — it is hard to get wrong and produces a properly configured account.
useradd: The Low-Level POSIX Tool
useradd is a lower-level command available on every Linux distribution (including Fedora, Arch, and all others). It does exactly what you specify and nothing more — by default it does not create a home directory, does not set a password, and does not prompt for any information.
Basic useradd with common options:
$ sudo useradd -m -s /bin/bash -c "Sarah Johnson" sarah
Breaking down the flags:
-m— create a home directory (at/home/sarahby default)-s /bin/bash— set the default shell-c "Sarah Johnson"— set the GECOS comment (full name)
After useradd, the account exists but has no password — the account is locked. Set a password immediately:
$ sudo passwd sarah
New password:
Retype new password:
passwd: password updated successfully
Common useradd options:
$ sudo useradd -m -d /home/sarah -u 1500 -s /bin/bash -c "Sarah Johnson" -g staff -G sudo,developers sarah
-d /home/sarah— specify home directory path (defaults to/home/username)-u 1500— specify a particular UID instead of using the next available-g staff— set the primary group (must already exist)-G sudo,developers— add to additional supplementary groups-e 2026-12-31— set account expiration date-k /etc/skel— specify a different skeleton directory
adduser vs useradd: When to Use Each
Use adduser (Ubuntu/Debian) when:
- Creating user accounts interactively on a desktop or server
- You want the safe, automatic behavior (home directory created, skeleton copied, permissions set correctly)
- You are on a Debian/Ubuntu system and simplicity is preferred
Use useradd when:
- You are writing scripts or automating user creation (its non-interactive nature is an advantage)
- You are on a non-Debian system (Fedora, Arch, etc.) where
addusermay not be available or may behave differently - You need precise control over every parameter
Creating a System Account (No Login)
System service accounts run programs (web servers, databases, etc.) but should not be used for interactive login. Create them without a home directory and with /usr/sbin/nologin as their shell:
$ sudo useradd --system --no-create-home --shell /usr/sbin/nologin webserver
Or with adduser on Debian/Ubuntu:
$ sudo adduser --system --no-create-home --disabled-login webserver
System accounts receive UIDs in a lower range (typically 1–999) and have nologin as their shell, preventing interactive use while still allowing them to own files and run processes.
Setting and Managing Passwords
Setting a Password for Any User
$ sudo passwd username
Prompts for the new password twice. There is no echo — the password is not displayed as you type.
Changing your own password (no sudo required):
$ passwd
Password Expiration and Aging
The chage command (change age) manages password aging policies:
$ sudo chage -l username
Shows the current password aging information:
Last password change : Feb 18, 2026
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
Set password to expire in 90 days:
$ sudo chage -M 90 username
Force a password change on next login:
$ sudo chage -d 0 username
Setting the last password change date to 0 (epoch) forces an immediate password change at next login — useful when creating accounts for others and wanting to ensure they set their own password.
Set account expiration date:
$ sudo chage -E 2026-12-31 username
After the expiration date, the account cannot be used for login even if the password is valid.
Locking and Unlocking Accounts
Lock an account (prevent login without deleting):
$ sudo passwd -l username
Prepends ! to the password hash in /etc/shadow, making the hash invalid and preventing login. The account and its files remain intact.
Unlock an account:
$ sudo passwd -u username
Check account lock status:
$ sudo passwd -S username
sarah L 02/18/2026 0 99999 7 -1
The second field shows the status: L (locked), P (password set), or NP (no password).
Modifying Existing User Accounts
The usermod command modifies properties of an existing user account.
Changing the Shell
$ sudo usermod -s /bin/zsh sarah
List available shells:
$ cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/usr/bin/sh
/bin/dash
/usr/bin/dash
/bin/zsh
/usr/bin/zsh
Only shells listed in /etc/shells are considered valid login shells. Setting a shell not in this file may prevent login.
Prevent login (useful for service accounts):
$ sudo usermod -s /usr/sbin/nologin username
Changing the Home Directory
Change home directory path (does not move existing files):
$ sudo usermod -d /new/home/path username
Change home directory and move files:
$ sudo usermod -d /new/home/path -m username
The -m flag moves existing home directory contents to the new location.
Changing the Username
$ sudo usermod -l newname oldname
This renames the account but does not rename the home directory. To rename both:
$ sudo usermod -l newname -d /home/newname -m oldname
Renaming the Primary Group
When you rename a user, their primary group (which usually has the same name) is not automatically renamed:
$ sudo groupmod -n newname oldname
Changing the Comment (Full Name)
$ sudo usermod -c "Sarah A. Johnson" sarah
Setting Account and Password Expiration via usermod
$ sudo usermod -e 2026-12-31 username # Account expires December 31
$ sudo usermod -e "" username # Remove expiration
Managing User Group Memberships
Groups are central to Linux’s multi-user permission system. A user’s group memberships determine which shared resources they can access.
Adding a User to a Group
The correct method — append without removing from other groups:
$ sudo usermod -aG groupname username
The -a (append) flag is critical. Without -a, usermod replaces all current group memberships with the specified group — removing the user from all other groups. Always use -aG together when adding to a group.
Adding to multiple groups at once:
$ sudo usermod -aG sudo,developers,docker sarah
The change takes effect at next login. Current sessions do not see new group memberships until the user logs out and back in. For immediate effect in the current shell session:
$ newgrp groupname
Removing a User from a Group
$ sudo gpasswd -d username groupname
Checking Group Memberships
$ groups sarah
sarah : sarah sudo developers docker
$ id sarah
uid=1000(sarah) gid=1000(sarah) groups=1000(sarah),27(sudo),1001(developers),998(docker)
Switching Between Users
The su Command
su (substitute user) allows switching to another user account:
$ su - username
Password:
The - flag loads the target user’s full environment (as if they logged in fresh). Without -, the current environment is largely preserved.
Switch to root:
$ su -
Password:
On Ubuntu where root has no password, this fails. Use sudo -i instead.
Run a single command as another user:
$ su -c "command to run" username
sudo -u: Run Commands as Another User
$ sudo -u www-data ls /var/www/html
Runs ls /var/www/html as the www-data user — useful for testing file access from another user’s perspective.
Removing Users
Removing a user account should be done carefully — especially regarding what happens to their files.
deluser: The Friendly Removal Tool (Ubuntu/Debian)
$ sudo deluser username
Removes the user account but preserves the home directory and all their files. This is the safest default — files remain accessible to root and can be archived before deletion.
Remove user and their home directory:
$ sudo deluser --remove-home username
Remove user, home directory, and all their files anywhere on the system:
$ sudo deluser --remove-all-files username
Use --remove-all-files with caution — it searches the entire filesystem for files owned by this user and removes them, which can take a long time on large systems and may affect shared files.
Remove user and their primary group (if the group has no other members):
$ sudo deluser --remove-home username
deluser automatically removes the user’s primary group if it was created just for this user and has no other members.
userdel: The Low-Level Removal Tool
$ sudo userdel username
Removes the account from /etc/passwd and /etc/shadow but leaves the home directory intact.
Remove account and home directory:
$ sudo userdel -r username
The -r (remove) flag deletes the home directory and mail spool. Files owned by this user elsewhere on the filesystem are not touched — they become “orphaned” files owned by a UID with no corresponding account.
Before Removing: Good Practices
Back up the user’s data:
$ sudo tar -czvf /backup/sarah_files_$(date +%Y%m%d).tar.gz /home/sarah/
Find all files owned by the user anywhere on the system:
$ sudo find / -user sarah -type f 2>/dev/null
Find orphaned files after deletion (files owned by the former UID):
$ sudo find / -uid 1000 -type f 2>/dev/null
Kill any processes the user is running before deletion:
$ sudo pkill -u username
$ sudo killall -u username
Removing an account while the user is logged in or has running processes can leave dangling processes and open files.
Viewing User Information
The id Command
$ id sarah
uid=1000(sarah) gid=1000(sarah) groups=1000(sarah),27(sudo),1001(developers)
Shows UID, primary GID, and all group memberships.
The finger and w Commands
$ finger sarah
Login: sarah Name: Sarah Johnson
Directory: /home/sarah Shell: /bin/bash
Last login Wed Feb 18 09:22 (UTC) on pts/0 from 192.168.1.100
finger may need installation: sudo apt install finger
$ w
09:35:42 up 5 days, 2:18, 2 users, load average: 0.12, 0.08, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
sarah pts/0 192.168.1.100 09:22 1.00s 0.08s 0.03s bash
root pts/1 192.168.1.105 09:30 5.00s 0.05s 0.01s w
Shows who is currently logged in, from where, when they logged in, and what they are doing.
Listing All User Accounts
$ cat /etc/passwd | grep -v "nologin\|false" | cut -d: -f1
Lists only accounts with real login shells (excludes service accounts).
More elegant with awk:
$ awk -F: '$7 !~ /nologin|false/ {print $1}' /etc/passwd
List all users with their UIDs:
$ awk -F: '{print $1, $3}' /etc/passwd | sort -k2 -n
User Account Configuration Files
Several configuration files affect how new user accounts are created.
/etc/default/useradd
This file sets defaults for the useradd command:
$ cat /etc/default/useradd
# Default values for useradd(8)
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no
HOME— base directory for home directoriesSHELL— default shell for new usersSKEL— skeleton directory for new home directoriesEXPIRE— default account expiration (empty = never)
Modify these defaults to change behavior for all new accounts created with useradd.
/etc/login.defs
This file controls system-wide user account settings:
$ grep -v "^#\|^$" /etc/login.defs | head -20
MAIL_DIR /var/mail
FAILLOG_ENAB yes
LOG_UNKFAIL_ENAB no
LOG_OK_LOGINS no
SYSLOG_SU_ENAB yes
SYSLOG_SG_ENAB yes
FTMP_FILE /var/log/btmp
SU_NAME su
HUSHLOGIN_FILE .hushlogin
ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
TTYGROUP tty
TTYPERM 0600
UMASK 022
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_WARN_AGE 7
UID_MIN 1000
UID_MAX 60000
GID_MIN 1000
GID_MAX 60000
Key settings:
UID_MIN/UID_MAX— range for regular user UIDs (1000–60000 on Ubuntu)PASS_MAX_DAYS— maximum days before password must be changedUMASK— default file creation mask for new users
/etc/skel: Skeleton Directory
Every new user’s home directory is populated with copies of files from /etc/skel:
$ ls -la /etc/skel/
total 28
drwxr-xr-x 2 root root 4096 Jan 15 2026 .
drwxr-xr-x 96 root root 4096 Feb 18 2026 ..
-rw-r--r-- 1 root root 220 Jan 15 2026 .bash_logout
-rw-r--r-- 1 root root 3526 Jan 15 2026 .bashrc
-rw-r--r-- 1 root root 807 Jan 15 2026 .profile
To give all new users a custom configuration — a personalized .bashrc, a README.txt explaining the system, or a pre-created projects/ directory — add those files to /etc/skel. Every user created after that modification will receive those files in their home directory.
Practical Scenarios
Scenario 1: Setting Up a New Team Member
A new developer joins the team and needs an account with appropriate access:
# Create the account
$ sudo adduser alice
# Add to necessary groups
$ sudo usermod -aG sudo,developers,docker alice
# Force password change on first login
$ sudo chage -d 0 alice
# Verify the setup
$ id alice
uid=1001(alice) gid=1001(alice) groups=1001(alice),27(sudo),1001(developers),998(docker)
Scenario 2: Temporarily Disabling an Account
An employee is on extended leave and should not be able to log in:
# Lock the account
$ sudo passwd -l bob
# Verify it is locked
$ sudo passwd -S bob
bob L 02/18/2026 0 99999 7 -1
# When they return, unlock
$ sudo passwd -u bob
Scenario 3: Cleanly Removing a Departed Employee
An employee has left the company; their account needs to be removed:
# First, archive their data
$ sudo tar -czvf /archive/bob_$(date +%Y%m%d).tar.gz /home/bob/
# Kill any running processes
$ sudo pkill -u bob
# Remove account but keep home directory (safer)
$ sudo deluser bob
# Or remove everything at once
$ sudo deluser --remove-home bob
# Verify removal
$ id bob
id: 'bob': no such user
Scenario 4: Creating a Shared Service Account
A web application needs to run under its own account:
# Create system account without login capability
$ sudo useradd --system \
--no-create-home \
--shell /usr/sbin/nologin \
--comment "Web Application Service Account" \
webapp
# Create application directory owned by this account
$ sudo mkdir -p /opt/webapp
$ sudo chown webapp:webapp /opt/webapp
# Verify
$ id webapp
uid=998(webapp) gid=998(webapp) groups=998(webapp)
$ ls -la /opt/
drwxr-xr-x 2 webapp webapp 4096 Feb 18 09:22 webapp
Quick Reference: User Management Commands
| Task | Ubuntu/Debian | Any Distribution |
|---|---|---|
| Create user (interactive) | sudo adduser username |
— |
| Create user (scripted) | — | sudo useradd -m -s /bin/bash username |
| Set password | sudo passwd username |
sudo passwd username |
| Remove user (keep files) | sudo deluser username |
sudo userdel username |
| Remove user + home dir | sudo deluser --remove-home username |
sudo userdel -r username |
| Add user to group | sudo usermod -aG group username |
sudo usermod -aG group username |
| Remove from group | sudo gpasswd -d username group |
sudo gpasswd -d username group |
| Change shell | sudo usermod -s /bin/zsh username |
sudo usermod -s /bin/zsh username |
| Lock account | sudo passwd -l username |
sudo passwd -l username |
| Unlock account | sudo passwd -u username |
sudo passwd -u username |
| Check account info | id username |
id username |
| List all users | cut -d: -f1 /etc/passwd |
cut -d: -f1 /etc/passwd |
| Force password change | sudo chage -d 0 username |
sudo chage -d 0 username |
| Set account expiry | sudo chage -E 2026-12-31 username |
sudo chage -E 2026-12-31 username |
| View password aging | sudo chage -l username |
sudo chage -l username |
Conclusion: User Management as Foundation
User management is foundational Linux administration — it is the system by which Linux enforces its multi-user security model, controls access to resources, and organizes the people and services that use a system. Whether you are managing a single personal machine, a shared family computer, a development server with a team of engineers, or an enterprise system with hundreds of accounts, the same tools and concepts apply.
The key principles to carry forward: use adduser for interactive user creation on Ubuntu/Debian, useradd for scripts and non-Debian systems; always use usermod -aG (with the -a flag) when adding users to groups; lock accounts rather than deleting them when temporary deactivation is needed; back up user data before deletion; and understand the files (/etc/passwd, /etc/shadow, /etc/group) that store everything the user management system builds.
With these tools mastered, you have the ability to structure your Linux system’s user landscape deliberately and securely — giving people and services exactly the access they need, no more and no less.




