Skip to main content
In this lesson you’ll learn how to create, modify, and delete Linux user accounts from the command line. We’ll also show how to verify the changes by inspecting system files and using commands like id, getent, and passwd -S. By the end you’ll understand the common user-management commands (useradd, usermod, userdel) and the system changes they produce. Note: these examples assume you are running as the root user. If you are not root, prefix the commands with sudo. Resources:

Verify accounts and system files

Use these commands to inspect accounts and groups:
  • Show user identity and groups:
  • Lookup user entry in system databases (works with NSS like LDAP):
  • Check /etc/passwd and /etc/group directly (local files):

Create users

  • Create a basic user user1 (no home by default on some distros):
Verify the account and its primary group:
Expected sample id output (UID/GID numbers vary):
  • Create user2 with a custom home directory and ensure the home is created (-m and -d):
Verify:
  • Create user3 with a specific UID:
Expected:
  • Create a non-login/system-style account user4 by setting the shell to /sbin/nologin:
  • Create user5 with an existing primary group student (the student group must already exist):
Expected (if student has GID 1000):
  • Create user6 and add it to the wheel group as a supplementary group:
Expected output showing wheel membership (UID/GID numbers may differ):

Modify users

Use usermod to change existing accounts.
  • Rename user1 to newuser1:
Note: renaming a user does not automatically rename the home directory. To rename the account and move its home directory, include -d and -m:
  • Add user2 to the wheel group without removing existing supplementary groups (append with -aG):
  • Change the login shell for user5 to /bin/bash:
  • Lock user4 to disable password-based logins:
Expected passwd -S output after locking (format varies by distro):

Provide default files for new users

Files in /etc/skel/ are copied into new users’ home directories when you create homes with useradd -m.
  • Create a welcome file in /etc/skel/:
  • Create a new user user7 to test that the welcome file is copied:
You should see /home/user7/welcome and the message you added.

Delete users

  • Delete user4 (removes only the user account, not the home directory):
  • Delete user5 and remove its home directory and mail spool (-r):
Confirm deletion by checking the passwd database:

Quick reference — common options

Summary

  • useradd — create user accounts. Useful options: -m, -d, -u, -s, -g, -G.
  • usermod — modify existing accounts. Common options: -l, -d -m, -s, -aG, -L.
  • userdel — remove accounts; add -r to delete home directories and mail spools.
  • Put default files in /etc/skel/ to have them copied into new users’ homes when using useradd -m.
  • Verify accounts with id, getent passwd, getent group, or by inspecting /etc/passwd and /etc/group.
Always ensure any groups you reference (for example student or wheel) exist before assigning them as primary or supplementary groups. Use getent group <groupname> to check.

Watch Video