Managing accounts and passwords

Beginner · 8 min

Creating, changing, locking and removing accounts with useradd, usermod, passwd and chage, and the defaults in /etc/login.defs and /etc/skel behind them.

Before thisUsers, groups and the account files

Learn Linux TV · 16 min · from 7:47

Managing accounts and passwords

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Learn Linux TVReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • useradd is the low-level tool on every distribution and does only what its flags and defaults say. Pass -m to create a home directory and -s to set a shell, or check /etc/default/useradd first. Debian's adduser is a friendlier wrapper.
  • New accounts take their UID range, password ageing and hash method from /etc/login.defs, and the files in their new home from /etc/skel.
  • usermod -G replaces a user's supplementary groups. Always use usermod -aG to add one, and remember group changes apply to new logins only.
  • passwd -l locks only the password; an SSH key still works. To shut an account off, expire it with usermod --expiredate 1 as well.
  • chage sets password ageing and account expiry. Current NIST guidance says not to force periodic password changes, but account expiry dates for contractors and temporary access are still useful.

Accounts are records, and tools keep them consistent

An account is a few lines spread across /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow, plus a home directory, as the previous lesson showed. You could edit those files by hand. People did, and corrupted them. The shadow-utils commands, useradd, usermod, userdel, groupadd, passwd and chage, exist to change all the right files together, with locking, and to apply site defaults. They are the same commands on Debian, Ubuntu, Fedora and RHEL.

Creating accounts

useradd is deliberately literal. It does what its flags and defaults say and nothing more, and the defaults differ by distribution. I read them from the official container images:

# debian: /etc/default/useradd (non-comment lines)
SHELL=/bin/sh
# fedora: /etc/default/useradd
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

and Fedora’s /etc/login.defs has CREATE_HOME yes while Debian’s does not. So on Debian a bare useradd bob makes an account with no home directory and /bin/sh as its shell. The useradd(8) man page explains: -m will “create the user’s home directory if it does not exist”, copying in the skeleton directory, and without -s it uses “the SHELL variable specified in /etc/default/useradd”. Be explicit, as Jay LaCroix advises in the video:

sudo useradd -m -s /bin/bash -c "Alice Smith" alice
sudo passwd alice

Debian and Ubuntu also ship adduser, an interactive wrapper that creates the home, asks for a password and applies Debian’s conventions. It is fine at the keyboard; in scripts, prefer useradd with explicit flags because it behaves the same everywhere.

For service accounts, useradd --system picks a UID from the system range and, per the man page, creates the account “with no aging information in /etc/shadow”. Add -s /usr/sbin/nologin and usually -M for no home. Many services now let systemd create the user instead, which the services group covers.

The defaults behind it: login.defs and skel

/etc/login.defs holds the site policy that useradd, passwd and friends read. In all three images I checked, Debian 13, Ubuntu 24.04 and Fedora 45:

UID_MIN    1000        UID_MAX    60000
PASS_MAX_DAYS  99999   PASS_MIN_DAYS  0   PASS_WARN_AGE  7
USERGROUPS_ENAB yes

HOME_MODE is 0700 on Debian and Fedora and 0750 on Ubuntu 24.04, so on Ubuntu other members of a user’s group can list their home. ENCRYPT_METHOD is YESCRYPT on Debian and Fedora and SHA512 in Ubuntu 24.04’s file. PASS_MAX_DAYS 99999 effectively means passwords never expire.

/etc/skel is the template for a new home directory. Debian’s holds .bash_logout, .bashrc and .profile; Fedora’s has .bash_logout, .bash_profile and .bashrc. Put a site-wide default dotfile here, and it lands in every home created afterwards. Existing users are not touched.

Changing accounts

usermod changes an existing account: -s for the shell, -d -m to move the home, -l to rename, -L and -U to lock and unlock. The one flag that bites everyone is -G. The man page: “If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends.” So:

sudo usermod -aG docker alice     # add a group: correct
sudo usermod -G docker alice      # replace all groups: probably not what you meant

Group membership is read at login, so the user must log out and in, or start a new session with newgrp, before it applies.

userdel -r alice removes the account and its home directory and mail spool. Files elsewhere owned by her UID stay, now showing a bare number; find them with find / -uid 1003.

Passwords, locking and expiry

passwd sets a password, or another user’s when run as root. passwd -S alice prints a status line whose second field is L (locked), NP (no password) or P (usable password).

Locking needs care. The passwd(1) man page says -l adds a ! to the hash, and warns: “Note that this does not disable the account. The user may still be able to login using another authentication token (e.g. an SSH key). To disable the account, administrators should use usermod –expiredate 1”. When someone leaves, lock the password, expire the account, and remove their keys from ~/.ssh/authorized_keys.

chage manages the ageing fields in /etc/shadow. chage -l alice lists them. chage -E 2027-03-31 contractor sets an account expiry date, which suits temporary access. Avoid -E 0 as a shortcut for “expire now”: shadow(5) warns that 0 “is interpreted either as an account with no expiration or as an expiration date of 1970-01-01”, which is why the passwd man page uses 1. chage -d 0 alice forces a password change at next login, handy after setting a temporary one. -M, -m and -W set maximum age, minimum age and warning days.

Should you force regular password changes with -M 90? Current guidance says no. NIST SP 800-63B-4 states verifiers “SHALL NOT require subscribers to change passwords periodically”, but “SHALL force a change if there is evidence that the authenticator has been compromised”. Forced rotation tends to produce predictable passwords. On servers the better answer is usually no passwords at all for SSH, only keys, as the devops lesson on SSH keys and bastions argues.

About the video

The embed is the main part of Learn Linux TV’s “Linux Crash Course - Managing Users”, July 2021, from “Adding Users” to “Creating a System User” (about 16 minutes). It covers useradd and its defaults, why to be explicit, userdel with and without the home directory, passwd for yourself and other users, and system users, on a live server. The closing chapters on the account files are the embed for the previous lesson. It does not cover usermod -aG, chage or /etc/skel in depth; the two shorter Learn Linux TV videos in deeper cover chage and passwd locking. I judged it from the chapters and description, and English from the original English audio track.

What was run: reading /etc/default/useradd, /etc/login.defs and /etc/skel from the downloaded Debian, Ubuntu and Fedora images, on a Mac. Command behaviour is quoted from useradd(8), usermod(8), passwd(1) and chage(1) on man7.org, and the password guidance from NIST SP 800-63B-4, checked 2026-11-28.

Check yourself

  1. 01You run usermod -G docker alice and she loses access to sudo. What went wrong?

    -G without -a replaces the whole supplementary group list, so alice was removed from sudo. The command should have been usermod -aG docker alice.

  2. 02You lock an employee's account with passwd -l when they leave, but they can still log in over SSH. Why, and what should you do?

    passwd -l only puts ! in front of the password hash. Key-based SSH does not use the password. Expire the account with usermod --expiredate 1, and remove their authorized keys.

  3. 03On Debian, useradd bob creates an account with no home directory and /bin/sh as the shell. Why?

    useradd only creates a home directory with -m (or when CREATE_HOME is set in login.defs), and Debian's /etc/default/useradd sets SHELL=/bin/sh. Pass -m -s /bin/bash, or use adduser.

  4. 04Where would you put a default .bashrc that every new user should get?

    In /etc/skel. useradd -m copies its contents into each new home directory.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark