5.5. Authentication and Session Policy
Passwords, aging rules, and login restrictions are enforced by one
framework for every entry point on the system: PAM, the Pluggable
Authentication Modules. A password checked at the console, over SSH, by
su, or by sudo travels through a PAM stack configured for that service;
the stacks share the account databases of Section 5.1.2. This section
covers what is stored, what the shared policy does, and how to restrict and
diagnose it.
5.5.1. Password Storage, Aging, and Account Expiration
Where the hashes live, and who may read them, is a boundary enforced by file permissions. In the root shell:
# ls -l /etc/passwd /etc/group /etc/shadow /etc/gshadow
-rw-r--r-- 1 root root 925 Nov 18 16:17 /etc/group
-rw-r----- 1 root shadow 772 Nov 18 16:17 /etc/gshadow
-rw-r--r-- 1 root root 2198 Nov 18 16:17 /etc/passwd
-rw-r----- 1 root shadow 1124 Nov 18 16:17 /etc/shadow
(ls sorts its operands, so the listing is alphabetical rather than in the
order named.) The pair readable by all carries identity; the pair readable
by root and the shadow group carries secrets. From sam's shell:
$ cat /etc/shadow
cat: /etc/shadow: Permission denied
Sam is not root and not in shadow, so the read fails at the permission
check of Section 5.3.1 - 0640 root:shadow is the whole mechanism. Root,
reading the same entry, can see the hash's form without exposing it:
# getent shadow john | cut -d: -f2 | cut -c1-3
$y$
The stored value is not the password but a one-way hash, salted per
account; $y$ says the scheme is yescrypt, the default this installation
recorded as ENCRYPT_METHOD YESCRYPT in Section 5.1.1. The scheme is chosen
when the password is set, so an account carried forward from an older
system can carry an older prefix; every prefix the tools understand:
| Prefix | Scheme | Note |
|---|---|---|
$y$ |
yescrypt | Debian 13 default; memory-hard. |
$6$ |
SHA-512 | Long-standing earlier default; still accepted. |
$5$ |
SHA-256 | Older still. |
$1$ |
MD5 | Obsolete; only for reading legacy entries. |
! |
Locked | passwd -l; Section 5.2.3. |
Password aging is a per-account policy: how long a password is valid, how soon it may be changed again, and when the account itself ends. An ordinary user can read their own state:
$ passwd -S john
john P 2026-11-18 0 99999 7 -1
The same fields passwd -S sam showed in Section 5.2.1: state P, last
change on Nov 18, no minimum age (0), effectively no maximum (99999 days),
seven days of warning, no inactivity limit. The long-form view:
$ chage -l john
Last password change : Nov 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
Everything is at its most permissive. A real policy ages passwords instead; set one for sam as an administrator would:
# chage -M 90 -m 7 -W 14 sam
chage printed nothing - it succeeded. Check the result:
# chage -l sam
Last password change : Nov 18, 2026
Password expires : Feb 16, 2027
Password inactive : never
Account expires : never
Minimum number of days between password change : 7
Maximum number of days between password change : 90
Number of days of warning before password expires : 14
Ninety days from the last change, the password expires; from day 76 the login warns for fourteen days; and a change made within seven days of the last one is refused, so a user cannot cycle back to a favorite. Restore the permissive defaults before continuing, so later sections behave as written:
# chage -M 99999 -m 0 -W 7 sam
chage option |
Description |
|---|---|
-l user |
List the aging policy in full sentences. |
-M days |
Maximum password age. |
-m days |
Minimum days between changes. |
-W days |
Days of warning before expiry. |
-E date |
Account expiry date; -1 disables it. |
-d date |
Set the last-change date (used when migrating policies). |
(passwd has equivalents - -x, -n, -w, and -i - acting on the same
fields; chage is the tool that also prints them.)
Account expiry, the end-of-employment lever from Section 5.2.3, is set with
chage -E just as with usermod -e. The demonstration is worth repeating
here because it completes the aging fields:
# chage -E 2020-01-01 sam
# chage -l sam
Last password change : Nov 18, 2026
Password expires : never
Password inactive : never
Account expires : Jan 01, 2020
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
$ su - sam -c 'id -un'
Password:
Your account has expired; please contact your system administrator.
su: Authentication failure
# chage -E -1 sam
# chage -l sam
Last password change : Nov 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
$ su - sam -c 'id -un'
Password:
sam
Password expiry and account expiry are independent: the first retires a
credential (and the user can fix it with passwd), the second retires the
account (and only an administrator can extend it). The distinction is why
Section 5.2.3 reached for expiry, not a lock, to suspend tempuser entirely.
5.5.2. Understanding PAM Configuration and Service Boundaries
Every service that authenticates users on Debian has a file under
/etc/pam.d:
$ ls /etc/pam.d
chfn
chpasswd
chsh
common-account
common-auth
common-password
common-session
common-session-noninteractive
cron
cups
lightdm
lightdm-autologin
lightdm-greeter
login
newusers
other
passwd
ppp
runuser
runuser-l
sshd
su
su-l
sudo
sudo-i
weston-remote-access
Each file is a stack: an ordered list of modules consulted for that service, grouped by facility. The four facilities divide the work of a login:
| Facility | Question it answers |
|---|---|
auth |
Who are you? Verify the password (or key, or token). |
account |
May you log in at all? Expiry, time of day, host restrictions. |
password |
How credentials are updated when you change your password. |
session |
What happens around the login: limits, umask, records. |
The common-* files are shared stacks that the per-service files include;
Debian generates them, and the generator - not a text editor - is the right
way to change them. The authentication stack in force on this installation:
$ grep -v "^#" /etc/pam.d/common-auth | sed "/^$/d"
auth [success=1 default=ignore] pam_unix.so nullok
auth requisite pam_deny.so
auth required pam_permit.so
Read it as a short-circuit: pam_unix checks the password against
/etc/shadow - nullok lets an account with an empty password field
authenticate without typing anything, while a locked account, whose stored
value starts with !, fails because no typed password can ever match the
prefixed hash. On
success, skip one line and land on pam_permit, which approves; on failure,
fall through to pam_deny, which refuses no matter what follows. The
bracketed control values ([success=1 ...], requisite, required) are
PAM's way of saying how much a module's verdict counts - pam.conf(5)
tabulates them, and this skip-ahead pattern is the standard Debian idiom
for "one real check, then a decisive fallback". The account stack is the
same shape:
$ grep -v "^#" /etc/pam.d/common-account | sed "/^$/d"
account [success=1 new_authtok_reqd=done default=ignore] pam_unix.so
account requisite pam_deny.so
account required pam_permit.so
Here pam_unix's account check enforces exactly what Section 5.5.1
configured: expiry dates and inactivity windows. The expired-account
message came from this module.
Service boundaries are per-file, and they explain behaviors this chapter
has already used. Root does not type a password for su:
# grep -n "pam_rootok" /etc/pam.d/su
/etc/pam.d/su:6:auth sufficient pam_rootok.so
/etc/pam.d/su:13:# permitted earlier by e.g. "sufficient pam_rootok.so").
pam_rootok succeeds when the caller is root, and sufficient means the
rest of the auth stack is skipped - the rule behind
Chapter 3's observation that root reaches any
account through su. Session policy is shared the same way; the limits
module of the next section appears in every interactive service:
$ grep -n "pam_limits" /etc/pam.d/su /etc/pam.d/sshd /etc/pam.d/login
/etc/pam.d/su:52:session required pam_limits.so
/etc/pam.d/sshd:40:session required pam_limits.so
/etc/pam.d/login:78:session required pam_limits.so
The framework itself is two packages:
# dpkg-query -W libpam-modules libpam-runtime
libpam-modules:amd64 1.7.0-5
libpam-runtime 1.7.0-5
libpam-runtime ships the generator pam-auth-update, which rebuilds the
common-* files from the profiles packages install into
/usr/share/pam-configs:
$ ls /usr/share/pam-configs
gnome-keyring
mkhomedir
systemd
unix
wtmpdb
$ cat /var/lib/pam/seen
unix
wtmpdb
systemd
mkhomedir
gnome-keyring
The profiles present on this system provide the classic Unix password stack
(unix), the session registration and umask handling (systemd), the login
records that last reads (wtmpdb), home-directory creation on first login
for directory-backed accounts (mkhomedir), and the desktop keyring
(gnome-keyring). Running pam-auth-update as root opens a menu of these
profiles and rewrites the shared stacks to match; package updates run it
automatically with the recorded selection. The practical rules follow from
that design: enable or disable whole features through the profile menu, add
service-specific rules in the service's file (never the generated
common-* files, whose headers say they will be overwritten), and expect a
profile-enabled module such as pam_umask to be present in the session
stack - it is the mechanism behind Section 5.3.3's 0002.
One more boundary module is active by default and worth knowing before it surprises you:
$ grep -n "pam_nologin" /etc/pam.d/login /etc/pam.d/sshd
/etc/pam.d/login:17:auth requisite pam_nologin.so
/etc/pam.d/sshd:7:account required pam_nologin.so
pam_nologin refuses non-root logins whenever the file /etc/nologin
exists, printing its contents as the reason. Systemd writes a copy in
/run/nologin while a shutdown or reboot is scheduled, which is why
planned-maintenance logins fail with a message about the system going down;
an administrator may also create the file by hand to freeze logins during
repair, and root is still admitted to clean up. Figure 5.5 shows the whole
arrangement.
Figure 5.5. Conceptual PAM layout: each service owns its file, pulls in the shared stacks, and the generator rebuilds the shared parts from profiles.
5.5.3. Session Limits and Login Restrictions
The session facility is where per-user resource policy lives. pam_limits
reads /etc/security/limits.conf and the drop-ins in
/etc/security/limits.d, and applies them at login time; because it runs in
the session stack, the limits reach every entry point - the grep above
showed it in su, sshd, and login alike.
Each rule is one line: a domain (a user, a group with @, a wildcard), a
type, an item, and a value. A small drop-in pins john's open-file limits:
Contents of /etc/security/limits.d/ch05-limits.conf:
john soft nofile 512
john hard nofile 1024
Create it:
# cat > /etc/security/limits.d/ch05-limits.conf <<'EOF'
john soft nofile 512
john hard nofile 1024
EOF
The file is written and nothing is printed. soft is the limit a session
starts with and the user may raise up to hard; hard is the ceiling the
user cannot pass. Limits apply to sessions that start after the change, so
log in again; in john's next SSH session:
$ ulimit -Sn
512
$ ulimit -Hn
1024
ulimit -Sn prints the soft open-file limit and -Hn the hard one; both
match the drop-in. The same policy follows the other entry points - here
checked through the root shell's su:
# su - john -c "ulimit -Sn"
512
And the hard ceiling is enforced against the user's own attempts to raise it:
$ ulimit -Hn 2048
bash: line 1: ulimit: open files: cannot modify limit: Operation not permitted
A process may lower its hard limit, and may raise the soft one up to hard,
but crossing the hard limit is exactly what pam_limits exists to prevent.
ulimit -a lists every limit of the current shell; the items an
administrator can pin include:
| Item | Controls |
|---|---|
nofile |
Open file descriptors per process. |
nproc |
Processes per user. |
cpu |
CPU time per process, in minutes. |
fsize |
Maximum file size a process may create. |
maxlogins |
Concurrent login ceiling for the user or group. |
as |
Address space per process. |
limits.conf(5) tabulates the rest, all enforced by the same mechanism;
maxlogins differs only in that the session exceeding the ceiling is
refused at login.
The other session restriction an administrator reaches for is closing an
account to interactive use without removing it. The tool is the shell
itself: /usr/sbin/nologin from Section 5.1.2, set as the login shell:
# usermod -s /usr/sbin/nologin sam
# getent passwd sam | cut -d: -f7
/usr/sbin/nologin
The change takes effect at the next login attempt - root's su needs no
password, but the shell still refuses to start:
# su - sam -c "id -un"
This account is currently not available.
One line, and the login ends. Authentication succeeds; the shell is a
program that immediately exits. Accounts closed this way keep their files,
their mail, and their group memberships, and reactivation is one usermod
away:
# usermod -s /bin/bash sam
Two further restriction mechanisms ship disabled by default and are worth
recognizing before enabling them. pam_access checks the host, user, and
time restrictions in /etc/security/access.conf; on this installation its
lines in the login and sshd stacks are commented out:
$ grep -n "pam_access" /etc/pam.d/login /etc/pam.d/sshd
/etc/pam.d/login:74:# account required pam_access.so
/etc/pam.d/sshd:11:# account required pam_access.so
Uncommenting the line in a service's file activates the module for that service; the rules then bar, for example, root logins from specific origins, or all logins outside working hours. The second mechanism is per-service configuration in the service itself - the SSH server's own policy on this installation:
# /usr/sbin/sshd -T | grep -E "^(passwordauthentication|pubkeyauthentication|permitrootlogin|usepam)"
usepam yes
permitrootlogin without-password
pubkeyauthentication yes
passwordauthentication no
sshd -T prints the effective configuration after includes and defaults,
which is why it is the reliable way to check what SSH enforces: this server
authenticates only by key (passwordauthentication no), consults PAM for
account and session policy, and admits root only by key. Where that
differs from what you need, the change belongs in sshd_config or its
drop-ins - Chapter 20 covers that file and the reload procedure
in full. The account-level tools of this chapter are unchanged by it: a
locked or expired account fails at the PAM account stage no matter which
methods sshd offers.
5.5.4. Diagnosing Authentication and Permission Failures
The layers of this chapter fail with distinguishable messages, and the fast path to a fix is identifying the layer before changing anything. The master table:
| Symptom | Layer | Check |
|---|---|---|
Permission denied reading a file |
Permission bits or ACLs | stat -c, getfacl -c, namei -l on the path. |
Permission denied executing a file |
Missing execute bit | stat -c, then chmod; exit status 126. |
Operation not permitted deleting a file |
Sticky bit on the directory | stat -c the directory; the ownership rule. |
su: Authentication failure, correct password |
Locked account | passwd -S user; state L. |
Your account has expired |
Account expiry | chage -l user; chage -E -1 to clear. |
This account is currently not available |
nologin shell |
getent passwd user, field 7. |
sudo: a password is required (with -n) |
Sudo policy | sudo -l, visudo -c. |
| Logins refused with a system message at every service | Login freeze | /etc/nologin and /run/nologin. |
For file paths, the diagnosis starts outside the file. namei -l walks the
path and shows every permission decision along the way:
$ namei -l /srv/handbook-project/report.txt
f: /srv/handbook-project/report.txt
drwxr-xr-x root root /
drwxr-xr-x root root srv
drwxrwsr-x john project handbook-project
-rw-r----- john project report.txt
Every step is traversable, and the file's own mode grants the group read -
the check a member of project needs would succeed. Had any directory in
the chain lacked x for the caller, the listing would show it exactly where
the path dies, which is why this command answers most "the permissions look
right but it still fails" reports: the permissions usually look right on the
file and wrong on a directory above it.
For logins, the system records what happened, and the records are readable as root. The login history first:
# last -n 5
john Wed Nov 18 16:17 - 16:17 (00:00)
sam Wed Nov 18 16:17 - 16:17 (00:00)
john Wed Nov 18 16:17 - 16:17 (00:00)
john Wed Nov 18 16:17 - 16:17 (00:00)
john Wed Nov 18 16:17 - 16:17 (00:00)
wtmpdb begins Wed Nov 18 16:17:05 2026
last -n 5 shows the five most recent sessions - who, when, from where, and
for how long; the trailing line names the record the wtmpdb profile
maintains and where its history begins. Which method a session used comes
from the service's journal:
# journalctl -u ssh --no-pager -n 200 | grep -F 'Accepted publickey for john' | tail -n 3
Nov 18 16:17:05 trixie sshd-session[553976]: Accepted publickey for john from 127.0.0.1 port 42932 ssh2: ED25519 SHA256:o1wSxCnjjGpHXTFoHaIlL23M+wWqaNC7JXa3mlwkiH4
Nov 18 16:17:10 trixie sshd-session[554031]: Accepted publickey for john from 127.0.0.1 port 42938 ssh2: ED25519 SHA256:o1wSxCnjjGpHXTFoHaIlL23M+wWqaNC7JXa3mlwkiH4
Nov 18 16:17:22 trixie sshd-session[554173]: Accepted publickey for john from 127.0.0.1 port 43612 ssh2: ED25519 SHA256:o1wSxCnjjGpHXTFoHaIlL23M+wWqaNC7JXa3mlwkiH4
The pipeline is one logical read: journalctl -u ssh -n 200 bounds the
recent history of the SSH unit, grep -F keeps the successful
authentications, and tail -n 3 the most recent three. Each line names the
method, the account, the origin address, and the key fingerprint - enough to
answer "was that really john, and how did they prove it". Failed
authentications appear in the same journal from the same unit, with the
reason in each line; sudo's records sit under its own tag as Section 5.4.2
showed.
Removing the practice environment. When you are finished with this chapter, remove what it created. The removals are destructive - they erase sam's account and home directory, the shared workspace with every file the permission and ACL examples made, and the two policy fragments - so run them only when the practice data is no longer needed:
# userdel -r sam
userdel: sam mail spool (/var/mail/sam) not found
# getent passwd sam
As before, the mail-spool note is harmless and the empty getent (exit
status 2) confirms the account is gone. The group and the workspace
follow:
# groupdel project
# getent group project
This next command deletes the whole practice tree at once:
# rm -rf /srv/handbook-project
It produced no output; report.txt, run-report.sh, the private,
dropbox, and shared directories, and every ACL entry on them went with
the directory. The two policy fragments belong to the cleanup as well - the
sudoers drop-in and the limits drop-in:
# rm /etc/sudoers.d/ch05-ops
# rm /etc/security/limits.d/ch05-limits.conf
Both are silent; visudo -c afterwards shows the policy reduced to the
stock files. Finally, in john's own shell, the private workspace:
$ rm -rf ~/debian-handbook/accounts-permissions
That clears the umask practice files and leaves ~/debian-handbook for the
next chapter's work.
The identity layer built here - accounts that exist, files that belong, elevation that is granted deliberately, and authentication that leaves records - is the substrate the rest of the book runs on: services run as system accounts (Chapter 8), remote administration rides on the same PAM and account state (Chapter 20), auditing counts exactly the setuid binaries, sudo rules, and password states this chapter taught you to inspect (Chapter 26), and centralized identity (Chapter 35) extends the same databases across many machines.