5.2 User & Group Account Lifecycle, Password Policies & chage
Key Takeaways
Local passwd, group and shadow records serve different purposes. Use getent for configured identity lookup and check the process’s real and effective credentials.
Check allocation ranges and account defaults on the host. The skeleton directory provides files for newly created homes, and login-shell initialization is separate.
When adding local supplementary groups, usermod -aG preserves existing memberships. Verify the account and a fresh session.
Password locks, password expiration, inactivity after expiration and account end dates are different controls. Read local aging with chage -l and password status with passwd -S.
Interpret who, w, last, lastb and lastlog according to the installed tools and the sessions or attempts the service records.
5.2 User & Group Account Lifecycle, Password Policies & chage
When provisioning or investigating an account, determine which identity source owns it, which credentials it may use, and which permissions or groups it should have. The following examples use a local account on a Linux host with the shadow utilities.
Identity records and lookup
| File | Local record and example |
|---|---|
/etc/passwd | Seven fields: login name, password field, UID, primary GID, GECOS comment, home directory, and login shell. In jdoe:x:1500:2300:Jane Doe:/home/jdoe:/bin/bash, x indicates that the password field is stored in shadow. This file is normally readable for local name resolution. |
/etc/group | Four fields: group name, password field, GID, and comma-separated member list. In qa:x:2400:alice,bob, a user can also have 2400 as their primary GID through the passwd record even if absent from this list. |
/etc/shadow | The protected local password and aging records. Check these through authorized account tools. Avoid printing credential hashes in logs or support transcripts. |
/etc/gshadow | The protected group data includes group administrators, the member list, and an optional group password field. |
The Name Service Switch uses configuration such as /etc/nsswitch.conf to resolve identities from local files and, where configured, providers such as SSSD. Use getent passwd jdoe or getent group qa for the configured lookup. id jdoe shows the resolved UID, primary GID and group memberships. NSS visibility can depend on backend, ordering, reachability and enumeration support. A returned identity alone establishes neither the active credentials of an existing process nor permission to log in.
A UID identifies the user numerically, and a GID identifies a group. A process also has an effective UID (EUID) and effective GID (EGID), which can differ from its real IDs after operations such as executing a permitted set-user-ID or set-group-ID program. Effective credentials, supplementary groups and applicable capabilities help determine access. In your shell, compare id -u with id -ru and id -g with id -rg. whoami prints the effective username.
UID 0 is the traditional root identity. Its available privileges also depend on capabilities and the user namespace. A system account may be reserved for a daemon or OS purpose, while a service account runs a particular workload and may be managed through local or external identity. Check UID_MIN, UID_MAX, SYS_UID_MIN, and SYS_UID_MAX in /etc/login.defs, and the corresponding GID settings. An allocation range helps explain how an ID was chosen. Look at account purpose, password state, shell and service policy to determine actual access.
Provisioning and modifying accounts
Review useradd -D and the distribution's /etc/default/useradd and /etc/login.defs. When useradd -m creates a new home, it populates it from the configured skeleton, usually /etc/skel. /etc/skel is a template copied at creation. /etc/profile is system-wide login-shell configuration on shells that read it. Bash initialization also depends on the invocation mode and installed dotfiles.
For an approved lab account, assume developers and qa exist and UID 1500 is free:
useradd -m -s /bin/bash -u 1500 -g developers -G qa -c 'Jane Doe' jdoe
getent passwd jdoe
id jdoe
The command selects a home, login shell, explicit UID, primary group, supplementary group and comment. A local password must be set separately if intended. Optional -d selects a home path and -e sets an account end date. If you omit the primary group, the result depends on the configured group policy. Use useradd -r when a system-range account is required. Its home and selected shell must fit the service's design. On Debian, adduser is a policy-aware front end for provisioning and deluser is the corresponding deletion tool. Read the installed implementation because the same command names can differ by distribution.
| Change | Shadow tools and checks |
|---|---|
| Add or change a local group | groupadd qa creates a group and groupadd -g 2400 qa requests an explicit GID. groupmod -n quality qa renames it. Changing a GID with groupmod -g updates affected primary-account records on the shadow implementation. Files with the old GID may need a separately planned ownership migration. |
| Append membership | With the target group already present, usermod -aG qa jdoe appends it. usermod -G qa jdoe replaces the managed supplementary list. Verify with id jdoe and check a fresh session because already running processes may retain the prior groups. |
| Change shell or home | chsh -s /bin/zsh jdoe selects a login shell when authorized. Nonprivileged shell changes normally use entries in /etc/shells. usermod -l changes the login name. usermod -d /home/newdir -m jdoe changes and attempts to move the home. Inspect owned files and processes before migration. |
| Retire a local account or group | userdel jdoe removes the local account records. Review retention and ownership before choosing userdel -r, which also removes the home and mail spool. Files elsewhere may still carry the old numeric UID. groupdel qa removes a local group once it is no longer needed as a primary group. |
Password aging, account expiration and lock state
A shadow entry has nine fields:
jdoe:!:20701:1:90:14:7:20818:
The example uses a locked password marker and no actual password hash. The date fields count UTC days from 1970-01-01. Use chage -l jdoe to read the local aging state and passwd -S jdoe to inspect password status. Compare these with the actual login service and external identity policy where relevant.
| Shadow field | Meaning and common control |
|---|---|
| 1, 2 | Login name and password field. A hash can represent a usable password. A leading ! locks the Unix password, and an unusable value such as * cannot match a password. An empty field allows passwordless acceptance only if the active service policy permits it. |
| 3 | Last change day. The special value zero requests a password change at the next login that honors local aging and supports changing the password. Set it with chage -d 0 jdoe or expire the password with passwd -e jdoe. |
| 4, 5 | Minimum and maximum password ages in days. chage -m sets the minimum and chage -M sets the maximum. A minimum of zero allows a change without a minimum wait. |
| 6, 7 | Warning days before password expiration and inactivity days after password expiration. Use chage -W and chage -I. The latter measures time since expiry, independent of the user's last activity. |
| 8, 9 | Account end date and a reserved field. Use chage -E 2026-12-31 jdoe to set the account end date or chage -E -1 jdoe to remove it. Account-aware login services check this date separately from password age. |
In this example, day 20701 is September 5, 2026. The 90-day value puts the reported password expiry date at December 4. The seven-day inactivity value puts the reported inactive date at December 11. The absolute account expiration is December 31. The lock marker still makes this example's Unix password unusable. For an active user who must rotate at first login, provision an approved initial credential and use a login method that actually supports the change.
passwd normally changes the invoking user's password. An administrator can use passwd jdoe to set that user's password through the configured mechanism. passwd -l or usermod -L locks the password. passwd -u or usermod -U can reverse that password lock when a usable credential remains. An SSH key or another credential can behave differently under the service's account checks. Expiring an account, checking PAM failure tallies, revoking other credentials and ending active sessions are distinct steps when offboarding requires them.
Apply the organization's applicable rules. NIST SP 800-63B-4 requires a change on evidence of compromise and prohibits requiring periodic password changes for subscribers in its scope. PCI DSS v4.x requirement 8.3.9 concerns applicable password-only user access and offers a 90-day change interval or dynamic analysis of account security posture with real-time access decisions. Common shadow settings implement local aging policy. Framework applicability depends on the service and assessment scope.
Current sessions and login history
| Need | Tool and interpretation |
|---|---|
| This process's identity | id and groups show current credentials or group memberships when invoked without an account operand. whoami gives the effective username. |
| Recorded active sessions | who shows recorded logins. w adds activity and a system load summary on procps systems. Output depends on which sessions are registered and the accounting backend. |
| Historical successful sessions | On a host using traditional util-linux accounting, last -n 10 reads recent entries from /var/log/wtmp, which can include reboots. |
| Failed attempts | On a host that provides lastb and records failures to /var/log/btmp, an administrator with access can use lastb -n 10. Check the affected service's logs for events absent from btmp. |
| Most recent login per account | lastlog reports records in the traditional lastlog database where supplied. Missing records can reflect coverage or retention. Debian 13 no longer ships these traditional commands in the same packages and documents replacements for last and lastlog. |
Local account mchen already belongs to the supplementary groups developers and training. The groups benchmarking and logs-readers exist. Which command adds both without removing existing memberships?
usermod -G benchmarking,logs-readers mchen
useradd -G benchmarking,logs-readers mchen
usermod -g benchmarking mchen
usermod -aG benchmarking,logs-readers mchen
A lab account with an approved usable initial password will sign in through a service that honors local shadow password aging and supports changing an expired password at login. Which command requires a new password on the next sign-in?
passwd -l dba_user
chage -d 0 dba_user
usermod --expiredate 1 dba_user
chage -m 0 dba_user
On a Debian 12 host with the traditional util-linux tools, the affected login service writes unsuccessful attempts to btmp. Which tool and file should an authorized administrator use to review those records?
last and /var/log/wtmp
lastlog and /var/log/lastlog
lastb and /var/log/btmp
who and the utmp data
Sections you finish are checked off in the contents.