Linux Password Policy: Configure PAM Rules

Linux Password Policy: Configure PAM Rules

Linux password rules can be stored in different places, depending on whether they check a new password or control when an account password expires. A Linux password policy combines password-quality checks with account settings that determine when passwords expire.

I’ll show how to inspect the active PAM password stack and read an account’s aging settings alongside defaults for new accounts.

TL;DR: Linux Password Policy

Linux password policy combines password-quality checks in PAM with expiry and warning fields stored for each account.

  • Read the active PAM password stack before changing its configuration.
  • When libpwquality is active, inspect its main file and configuration drop-ins.
  • Use chage -l username to read one account’s aging settings.
  • Check distribution guidance before editing files managed by PAM tools.

What Is a Linux Password Policy?

A Linux password policy defines rules that apply when users change passwords and when account passwords reach their expiry dates.

PAM, or Pluggable Authentication Modules, lets a service call configurable authentication modules. A password stack can place pam_pwquality ahead of the module that updates the password, so the order determines when the quality check runs.

System authentication components store password hashes, while PAM modules evaluate new candidates.

ControlWhere to inspectWhat it answers
Password qualityActive PAM password stack and pwquality settingsWhich checks apply to a proposed password
Password historyActive PAM stack and its history moduleWhether prior passwords are considered
Account agingOne account’s shadow aging fieldsWhen that account’s password expires or warns
New-account defaultslogin.defs and account-creation toolsWhich aging values new accounts receive
Root-set password checksQuality module optionsWhether a root-set password can be rejected
Directory account policyIdentity provider or directory serviceWhere managed accounts receive password rules

For account setup and administration, see Linux user administration. The guide to adding users to sudoers covers administrator permissions.

How to Check and Configure a Linux Password Policy

Begin by identifying the service and account you need to inspect, then choose the matching read-only command.

Choose inspection commands first because reading configuration avoids changing login behavior. The commands below show where to look.

Step 1: Read the active PAM password stack

Debian and Ubuntu commonly use common-password for the shared password stack. RHEL-family systems may use authselect to manage generated PAM files, so follow that distribution’s documented profile procedure.

grep -nE '^[[:space:]]*password' /etc/pam.d/common-password

The command lists password entries from the shared file. Locate pam_pwquality or pam_unix and read the arguments beside each module name.

Step 2: Inspect libpwquality settings

When libpwquality is active, system defaults can be set in pwquality.conf, with drop-ins under pwquality.conf.d taking precedence when they override a value.

Use the option names in the search to identify configured values and check the installed module manual before changing them.

grep -nE '^[[:space:]]*(minlen|difok|dcredit|ucredit|lcredit|ocredit|enforcing|retry)[[:space:]]*=' /etc/security/pwquality.conf /etc/security/pwquality.conf.d/*.conf
OptionEffect to verifyDecision question
minlenMinimum candidate lengthWhat length meets the system’s approved policy?
difokDifference from the previous passwordShould a new candidate differ by a specified amount?
dcreditDigit requirement or length contributionDoes the chosen sign require digits or affect length?
ucredit, lcredit, ocreditUppercase, lowercase, and other-character creditsWhich classes, if any, are required by local policy?
enforcingRejection or warning behaviorDoes the active module reject failed checks?
retryHow many password attempts the module allowsWhat limit does the installed module support?

The shell expands the *.conf wildcard before grep runs. If no drop-in matches, grep may report a missing literal path. Read that message alongside the main file before deciding whether drop-ins exist.

Step 3: Choose quality values for the system

Choose values for the affected account population and applicable policy, then use the configuration below to compare length and password-change controls.

minlen = 14
difok = 3
ucredit = 0
dcredit = 0
lcredit = 0
ocredit = 0
enforcing = 1
retry = 3

This set uses length and difference values without requiring character classes through negative credits. Confirm the installed module’s behavior with an approved account before wider use.

During an approved test, observe whether a candidate that fails the rule produces a warning or a rejected change. Check a permitted candidate separately, and keep the test account outside critical workflows.

Record the module version and active PAM profile alongside any approved values so later comparisons use the same change path.

Before adopting a valueReason to check
Confirm the governing policyLocal rules may come from an organization or service owner
Review affected servicesEach password-change path may load a different PAM stack
Check the installed manualThe manual documents option syntax and module-specific behavior
Test an approved accountA controlled test reveals whether the expected rejection occurs
Plan a rollbackA rejected change should not leave users without a recovery route

Step 4: Read aging settings for an account

chage -l username displays aging values stored for a named local account.

chage -l username

Replace username with the account name, and keep account details private when sharing diagnostic output.

Field in chage outputMeaning
Last password changeDate of the last password update
Minimum daysShortest interval before another change
Maximum daysInterval before the password expires
Warning daysNotice period before expiry
Password inactiveGrace period after expiry before the password is disabled
Account expiresDate the account itself becomes unavailable

Before an aging change, verify the details in this checklist.

CheckWhy it matters
Account name and sourceApply the change to the intended local or directory account
Approved minimum and maximum intervalsSet dates that match the organization’s rule
Warning periodGive users time to change an expiring password
Recovery pathRestore access if a chosen date blocks a user

For a planned change, check the local manual for -M and -W, then verify the resulting record with chage -l.

Step 5: Review defaults for new accounts

Inspect password-aging defaults in login.defs. New accounts can inherit these values, while existing accounts keep their recorded settings until an administrator changes them.

grep -nE '^[[:space:]]*PASS_(MAX_DAYS|MIN_DAYS|WARN_AGE)' /etc/login.defs
Default to compareAccount valueWhy compare
PASS_MAX_DAYSMaximum daysFind differences in expiry intervals
PASS_MIN_DAYSMinimum daysCheck how soon the user may change a password
PASS_WARN_AGEWarning daysConfirm that the account receives advance notice
Directory policyDirectory account settingsExplain values supplied outside local files

Review one representative account from each managed account class before applying the approved policy.

Account-creation tools can also set values when a new user is created. Compare their documented defaults with login.defs before changing a creation workflow.

See SSH key-based login for remote access and the guide to encrypting files or directories for file protection.

Common Errors and What to Check Next

Use the table to choose a focused follow-up because a warning and a missing setting call for different evidence.

SymptomLikely causeNext check
A warning appears, but the password change succeedsThe module may warn instead of rejecting, or root-specific settings may applyRead enforcement and root options in the active PAM stack and module manual
Changing pwquality.conf has no effectThe service may use another stack, skip the module, or pass overriding argumentsInspect the service stack and its effective module arguments
New and existing accounts have different expiry valuesNew-account defaults and stored aging records serve different purposesCompare login.defs with chage -l for an existing account
PAM edits disappear after a system updateA distribution tool may regenerate the configurationCheck the active profile and supported management procedure
A root-set password bypasses a quality failureRoot-specific enforcement may be disabledCheck enforce_for_root in the module manual
Password history is not checkedThe history module may be absent from the active stackCheck whether pam_pwhistory is installed and configured
Local account details conflict with central policyA directory or identity provider may own the account rulesInspect the account source and its policy interface
The shared PAM file is missingThe distribution uses a different file layoutFollow that system’s service-specific documentation
An empty pwquality search is returnedThe values may live in another drop-in or module argumentReview the complete configuration source in documented order
One application rejects a password while another accepts itThe applications can load different service stacksCompare the PAM files used by both password-change paths
A user receives no warning before expiryThe aging record or notification path may omit a warningCheck warning days and the user-facing notice mechanism
A directory user cannot change a password locallyThe directory may own password changes for that accountUse the provider’s supported policy and recovery path
Policy edge caseWhat to verify
Root-set password checksThe Ubuntu pam_pwquality manual documents enforce_for_root for rejecting failed checks. Root supplies no old password, so old-versus-new checks cannot run in that path.
Password historyLinux-PAM provides pam_pwhistory, but integration varies by distribution. Check the installed module manual for accepted options and placement before editing the service stack.

NIST’s fourth revision of Special Publication 800-63B advises covered verifiers against composition requirements and discusses blocklists and throttling. Its guidance addresses digital identity services.

A blocklist rejects candidate passwords known to be weak or exposed. Throttling slows repeated authentication attempts. A verifier can apply these checks alongside its other approved controls.

Set an expiry schedule when an applicable policy calls for it. Verify warning delivery and account recovery before enabling the schedule.

For host-level controls, read about Linux firewalls, SELinux and AppArmor.

Conclusion: Keep Policy Layers Separate

Use the distribution-supported mechanism for an approved change, then verify its effect with a controlled account test. Record the setting and the accounts covered by the policy.

For related account-security tasks, see password-protecting files.

FAQ

These answers point to the configuration layer that matches each question.

How do I check the password policy in Linux?

Inspect the active PAM password stack and its quality-module options, then run chage -l username to read one account’s aging settings. A local file may omit directory-managed rules.

Does changing login.defs update existing accounts?

login.defs supplies defaults for newly created accounts. Inspect existing account aging separately with chage -l.

What does dcredit=-1 mean in pwquality?

A negative dcredit value requires a minimum number of digits. A non-negative value contributes to the length calculation.

Does Linux require uppercase letters and symbols in passwords?

Linux has no single universal rule. PAM modules can enforce configured character classes, while the active stack and local policy determine what applies.

Why does a weak password warning still allow a change?

The active module may only warn, may be absent from the service stack, or may use root-specific behavior. Check the effective PAM options.