8.1 Account Hardening, PAM Security Modules & Least-Privilege Policies
Key Takeaways
Check the active PAM service and module arguments before relying on a password policy file.
Negative pwquality credits specify required counts. Set all remaining credits to zero when the lab requires a literal length floor.
Use faillock to inspect or clear one PAM tally. Check password locks and account expiration separately.
Use a dedicated identity with only the permissions a service needs. Review local console, SSH and alternate login paths independently.
8.1 Account Hardening, Authentication Policy & Least Privilege
Match the policy to the account's purpose and the service that authenticates it. Inspect the identity source, active PAM profile or other authentication policy, and the account's permissions before making changes. A local password setting may have little effect on an account owned by a remote identity provider.
Password policy, MFA and breach screening
Length, uniqueness, guessing resistance and protection against credential reuse serve different purposes. A composition rule can require classes of characters, but that rule alone does not measure entropy or prevent predictable choices. Require unique passwords and use approved screening for commonly used or compromised choices. For example, a verifier in scope of NIST SP 800-63B-4 compares prospective passwords against a blocklist that can include previous breach data. Avoid entering a real password into an unapproved external checker.
MFA combines distinct factor types. An approved password plus a separate hardware authenticator combines knowledge and possession. A password and an additional PIN are both knowledge factors in that simple example. Plan secure enrollment, recovery and deprovisioning of second factors. An SSH public key proves control of the matching private key. Whether the complete sign-in meets a particular MFA requirement depends on the configured authenticator and policy.
Choose expiration and reuse controls according to the applicable policy. NIST SP 800-63B-4 prohibits requiring periodic changes for subscriber passwords within its scope and requires a change on evidence of compromise. Other applicable requirements may differ. For a local shadow account, chage -l labuser shows aging, and chage -E 2026-12-31 labuser sets a specific account end date. The -I field measures days after password expiry. It does not measure days since the last login.
Validate the selected password change path
Where pam_pwquality.so is installed in the service's password stack, inspect its configuration, such as /etc/security/pwquality.conf, drop-ins and module arguments. Managed profiles can change what the service actually loads. A package or configuration file alone does not enforce a check.
| Setting | Effect in an applicable libpwquality configuration |
|---|---|
minlen | Length threshold used with the character credit settings. |
dcredit, ucredit, lcredit, ocredit | Represent digits, uppercase, lowercase and other characters. A negative value requires at least that many characters of the class. A positive value can grant length credit, and zero gives no credit. |
enforce_for_root | With the module active and enforcement enabled, quality failures can cause a change by root to be rejected. Checks requiring knowledge of the previous password may not run for a root-initiated reset. |
difok, maxrepeat | Control aspects of similarity to the old password and consecutive identical characters. Check the installed version and configuration before interpreting the result. |
For an illustrative local lab with ASCII-only test inputs, assume an enforcing module, no overrides and a requirement of at least 14 characters, one digit, one uppercase letter and enforced checks for root-initiated changes. The following avoids positive length credits:
minlen = 14
dcredit = -1
ucredit = -1
lcredit = 0
ocredit = 0
enforce_for_root
This example shows how to implement a specified rule. It is not a universal baseline. Use disposable test credentials and test the actual change operation. pwscore can help inspect library checks when supplied, but it is not proof that the target service loads a particular module or handles the result as intended.
Where pam_pwhistory.so is used, its remember setting limits reuse based on retained history. Its local history file typically defaults to /etc/security/opasswd. Protect it as sensitive data and check the distribution's supported permissions and configuration. A stack can use use_authtok to check the new token supplied by an earlier password module. Ensure the final update honors the history result. Local history cannot substitute for the password policy of an external directory.
Distinguish modern and legacy failure counters
On a host configured with Linux-PAM pam_faillock.so, check how the service uses it and where it stores data. A stack may check before authentication, record a failure on the failure path, and clear records on a qualifying success. In the module's auth-only design, preauth, authfail and authsucc have different roles. A documented alternative uses the account phase with its own integration requirements. An early success that bypasses a required tally operation can change which attempts are counted.
| Option in the active faillock policy | What it controls |
|---|---|
deny and fail_interval | Failure threshold and time window used by the configured stack. |
unlock_time | Wait before the temporary lock is lifted. Zero disables timed unlocking. A volatile tally directory may still lose records on reboot. |
even_deny_root, root_unlock_time, admin_group | Root handling, including a root-specific interval. The admin group follows the root treatment and is not necessarily exempt. |
dir | Tally directory. Inspect the common configuration and service-specific overrides. |
Use faillock --user labuser to view records for the effective configuration. If the confirmed cause is the tally and the change is approved, faillock --user labuser --reset clears it. Supply the matching configuration or directory where required. Verify a fresh authorized sign-in. A cleared tally does not unlock the Unix password, extend expiry, or alter SSH access controls.
The CompTIA objective also names pam_tally2, a legacy module and administration tool for failed login counts. Older Linux-PAM distributions that ship it can inspect a supported tally with pam_tally2 --user labuser. Upstream Linux-PAM removed the deprecated module in version 1.5.0. Identify the actual stack and distribution before choosing either tool. The two modules have different options, storage, and integration.
Service identities and restricted access
Use dedicated accounts and the minimum privileges and writable paths the service needs. For example, on a Linux lab host where /sbin/nologin exists, a local shadow account for a system service can be created with:
useradd -r -M -s /sbin/nologin labsvc
The system UID comes from the host's configured range. -M suppresses home creation. nologin refuses access when invoked as the account's shell. Verify the credentials recognized by the actual service. An account shell and a locked password do not govern every possible program launch or access method. A service manager can run the approved daemon with User=labsvc and the intended group independently of an interactive login shell.
/bin/rbash, where supplied, is a restricted Bash invocation. It limits operations such as changing directories or using certain command paths, but available programs and writable locations can undermine those restrictions. Treat it as one component of a restricted environment. Review privileged services and delegate narrow administrative actions. If a workload needs a capability, verify the actual kernel and namespace conditions before granting it. Use the SSH policy in the OS-hardening section for direct remote root access. A console restriction through pam_securetty applies only for services and implementations that use it.
A Linux lab password-change service runs pam_pwquality in enforcing mode with no module-argument overrides. For ASCII-only test inputs, the lab requires at least 14 characters, including one digit and one uppercase letter, and must reject a failing change made by root. Which combination in /etc/security/pwquality.conf meets those conditions?
minlen=14, dcredit=-1, ucredit=-1, lcredit=0, ocredit=0, enforce_for_root
minlen=14, dcredit=1, ucredit=1, lcredit=0, ocredit=0, enforce_for_root
minlen=14, dcredit=-1, ucredit=-1, lcredit=1, ocredit=1, enforce_for_root
minlen=14, dcredit=-1, ucredit=-1, lcredit=0, ocredit=0
A local Linux login service uses pam_faillock with unlock_time=0 and a persistent tally directory. The configured stack has blocked a regular user at the failure threshold, and the user’s Unix password is still usable. What does this setting imply for the tally lock after 20 minutes?
It expires at the end of the fail_interval window.
A password unlock with passwd -u clears the tally.
The tally has no time-based unlock. Confirm the cause and use the approved tally reset if needed.
The tally has no effect on login when the Unix password is usable.
On a Linux host using shadow-utils, /sbin/nologin exists and labsvc is a new local name. Which command chooses the configured system UID range, skips home-directory creation and assigns the non-login shell?
useradd -m -s /bin/bash labsvc
useradd -r -M -s /sbin/nologin labsvc
useradd -r -m -s /sbin/nologin labsvc
useradd -M -s /sbin/nologin labsvc
Sections you finish are checked off in the contents.