Skip to content

Linux PAM Configuration: Authentication and Access Policies

Linux PAM configuration is an essential part of managing authentication, account restrictions, and access policies on Linux servers. Pluggable Authentication Modules (PAM) provide a flexible framework that allows Linux applications and services to authenticate users without implementing every authentication method independently.

For administrators managing Linux VPS and dedicated servers, understanding PAM helps troubleshoot login failures, enforce account restrictions, and configure authentication policies safely. However, an incorrect PAM rule can prevent legitimate users from logging in, including administrators connecting through SSH.

In this guide, you will learn how Linux PAM works, how to inspect authentication stacks, how to configure common access policies, and how to test changes without locking yourself out of a server.

What Is Linux PAM?

PAM stands for Pluggable Authentication Modules. It is a framework that allows applications to use configurable modules for authentication and related account-management operations.

Instead of implementing every authentication method separately, a PAM-aware application can rely on the system’s configured authentication stack.

Linux PAM can help manage:

  • User authentication and password verification.
  • Account eligibility and access restrictions.
  • Password changes and password-quality requirements.
  • Session initialization and cleanup.
  • Additional authentication methods supported by installed modules.

For example, an SSH service may use PAM to perform account checks or support password-based authentication. A local login service may use PAM to authenticate a user and initialize the session.

PAM does not replace every Linux security mechanism. SSH keys, Unix file permissions, sudo rules, firewall policies, and application-specific authentication can operate alongside PAM or independently of it.

How Linux PAM Configuration Works

PAM processes configuration rules associated with a particular service and operation. The application requests a PAM operation, and the framework invokes the modules specified in the applicable configuration stack.

The four main PAM management groups are:

  • auth: Verifies a user’s identity and handles authentication-related operations.
  • account: Determines whether an account is eligible to access a service.
  • password: Handles password changes and related requirements.
  • session: Performs tasks when a session starts or ends.

Successful authentication does not necessarily mean a user is permitted to access a service. An account module may deny access because an account has expired or a configured restriction applies.

A simplified login process may involve authentication, account checks, session setup, and the application’s own access decisions. The exact sequence depends on the service and its configuration.

Step 1: Check PAM on Your Linux Server

Before changing authentication policies, identify the Linux distribution and installed PAM packages.

Check the operating system:

cat /etc/os-release

On Debian or Ubuntu, inspect the installed packages:

dpkg -l | grep -E 'libpam|pam'

On RHEL, Rocky Linux, AlmaLinux, or compatible systems, run:

rpm -qa | grep -i pam

List the service-specific PAM configuration files:

ls -la /etc/pam.d/

You may find files such as sshd, sudo, and login, along with shared configuration files. The exact layout depends on the distribution.

Do not create a missing PAM file blindly. First determine which package or service should provide it and whether the configuration is managed by a distribution-specific tool.

Step 2: Understand PAM Configuration Files

PAM configuration is commonly stored in /etc/pam.d/. Each service usually has its own configuration file, while shared files can contain common authentication rules.

An illustrative directory structure might look like this:

/etc/pam.d/
├── sshd
├── sudo
├── login
├── common-auth
├── common-account
├── common-password
└── common-session

This is not a universal layout.

Debian and Ubuntu commonly use files such as common-auth and common-account. RHEL-family systems may use system-auth and password-auth, with configuration managed through authselect.

A PAM configuration line generally contains a module type, control flag, module path, and optional arguments:

auth required pam_unix.so

Here, auth is the management group, required is the control flag, and pam_unix.so is the module.

Some files include other configuration files using directives such as include or substack. Understand these relationships before editing a service’s authentication stack.

Step 3: Understand PAM Control Flags

Control flags determine how each module’s result affects the overall stack.

required

The module must succeed for the overall stack to succeed. Processing usually continues through later modules even if this module fails.

requisite

The module must succeed. A failure normally stops the stack immediately.

sufficient

A successful result may allow the stack to succeed early if no previous required failure has occurred. A failure is generally not fatal by itself.

optional

The module’s result is usually not decisive when other modules determine the overall outcome, although the exact behavior depends on the stack.

PAM also supports extended control syntax that maps particular return values to actions. These rules can be powerful but difficult to interpret.

The order of modules matters. Two stacks containing the same modules can behave differently when the order or control flags change. Avoid copying a PAM configuration snippet into production without understanding its effect on the complete stack.

Step 4: Inspect the Active Authentication Stack

Before troubleshooting SSH login failures, inspect the relevant PAM file:

sudo sed -n '1,200p' /etc/pam.d/sshd

On Debian or Ubuntu, shared files may also need inspection:

sudo sed -n '1,200p' /etc/pam.d/common-auth
sudo sed -n '1,200p' /etc/pam.d/common-account
sudo sed -n '1,200p' /etc/pam.d/common-session

On RHEL-family distributions, inspect the applicable files and determine whether authselect manages them.

Check whether SSH is configured to use PAM:

sudo sshd -T | grep -i usepam

If the output is usepam yes, OpenSSH uses PAM for applicable authentication and account/session processing. Other SSH settings still influence the login process.

You can also check common PAM module directories:

ls -la /lib/security/ 2>/dev/null
ls -la /lib64/security/ 2>/dev/null

Module locations vary by distribution and architecture.

Step 5: Configure Account Access Restrictions

The pam_access.so module can enforce access rules based on users, groups, and origins, according to the configured policy and service context.

Rules are commonly defined in /etc/security/access.conf, although another file can be specified through module options.

For example:

-:guest:ALL

This illustrative rule denies the user guest access under the applicable pam_access policy.

However, the rule will not take effect simply because it exists in the file. The relevant PAM account stack must invoke the module, and the rule must match the actual login context.

A module entry may resemble:

account required pam_access.so

Do not add this line blindly to an active SSH configuration. First inspect the existing account stack and test the intended rule using a separate, non-privileged account.

When should you use PAM access rules?

PAM access rules can be useful when you need centralized access restrictions for PAM-aware services.

For SSH-specific restrictions, OpenSSH directives such as AllowUsers, AllowGroups, DenyUsers, and DenyGroups may be more appropriate. These are OpenSSH controls, not PAM directives.

Choose the narrowest control that meets the requirement, and verify how it interacts with existing authentication policies.

Step 6: Configure Password Policies

Password requirements can be implemented through PAM password modules and distribution-specific configuration.

For example, pam_pwquality.so can enforce password-quality rules when installed and configured appropriately.

A module entry might resemble:

password requisite pam_pwquality.so retry=3

This is an illustrative example, not a complete password policy. The effective behavior depends on the module configuration and the rest of the password stack.

Some distributions maintain password-quality settings in files such as /etc/security/pwquality.conf.

Before changing password rules, verify that the module is installed, inspect the existing stack, and follow your distribution’s documentation. Test password changes with a dedicated test account rather than experimenting with the only administrator account.

Step 7: Manage Failed Login Attempts

Repeated authentication failures can indicate password guessing, compromised credentials, or ordinary user mistakes.

On supported systems, pam_faillock.so can help manage failed-login attempts. The exact behavior depends on module placement, reset settings, control flags, and the distribution’s configuration.

On some RHEL-family systems, failed-login handling may be managed through authselect. Other distributions may use different modules or approaches.

Before implementing a lockout policy:

  1. Confirm which failed-login mechanism is already active.
  2. Read the documentation for the installed module and distribution.
  3. Define an appropriate failure threshold and unlock procedure.
  4. Consider the possibility of locking out legitimate users.
  5. Maintain an administrative session and verify recovery access.
  6. Test the policy using a separate account before deployment.

Do not copy a lockout configuration from another distribution without checking module order and existing rules.

For internet-facing SSH services, combine appropriate authentication policies with SSH key authentication, network restrictions where practical, and monitoring. PAM lockout rules are only one component of server security.

Step 8: Use Distribution-Specific PAM Management Tools

Some Linux distributions provide tools that manage PAM configuration. These tools are often safer than manually editing files generated by the operating system.

Debian and Ubuntu

On systems that use pam-auth-update, inspect the available profiles:

sudo pam-auth-update

This interactive tool can enable or disable supported PAM profiles. Review proposed changes carefully and back up the existing configuration before proceeding.

Not every PAM setting is managed by this tool, so service-specific files may still require inspection.

RHEL, Rocky Linux, and AlmaLinux

On systems using authselect, inspect the active configuration:

sudo authselect current

Check its consistency:

sudo authselect check

Use supported profiles and features for configuration changes where appropriate. Avoid directly editing generated files when the operating system expects authselect to manage them.

The commands and supported features depend on the installed version and selected profile.

Step 9: Test PAM Changes Without Locking Yourself Out

A PAM configuration can be syntactically valid and still prevent users from logging in. Testing is therefore essential.

1. Keep your existing administrative session open

Do not close your working SSH session while modifying PAM.

If a new login fails, the existing session may provide a way to investigate and restore the configuration. This is not guaranteed, so do not rely on it as your only recovery method.

2. Verify recovery access

Confirm that your hosting provider offers a web console, serial console, rescue environment, or another documented recovery method. Verify that you can access it before making high-risk authentication changes.

3. Back up the configuration

For example:

sudo cp -a /etc/pam.d/sshd \
  /etc/pam.d/sshd.backup

Back up shared files separately if you plan to modify them. On systems using a configuration-management tool, preserve the relevant profile information as well.

4. Use a separate test account

Test your changes with a non-privileged account. Avoid using your only administrator account as the first test subject.

5. Validate the configuration

PAM has no single universal command that fully validates every module and every service’s authentication behavior.

Check module availability, file syntax, distribution-specific configuration tools, and system logs.

For SSH, validate the daemon configuration:

sudo sshd -t

This checks OpenSSH configuration syntax. It does not prove that PAM authentication will succeed.

6. Test a new connection

Open a second terminal and attempt a new login using the test account and intended authentication method.

Test both permitted and denied scenarios. Keep the original session open until the new connection works as expected.

7. Review logs and roll back if necessary

On systems where the service is named ssh, inspect recent events with:

sudo journalctl -u ssh --since "10 minutes ago"

On systems where it is named sshd, use:

sudo journalctl -u sshd --since "10 minutes ago"

Some systems instead record authentication events in /var/log/auth.log or /var/log/secure.

If authentication breaks, use your existing administrative session or verified recovery console to restore the previous configuration. Avoid rebooting merely to test a PAM change.

Common Linux PAM Configuration Problems

SSH login fails after a configuration change

Inspect the SSH PAM stack, shared configuration files, module paths, and control flags. Check authentication logs and restore the previous configuration if needed.

Also verify SSH settings, account status, and authorized keys. Not every SSH failure originates in PAM.

A PAM module cannot be loaded

Check whether the module package is installed and whether its path is valid for your distribution and architecture. A missing module can cause the affected PAM operation to fail.

Account restrictions do not work

Confirm that the service invokes the relevant module and that the rule matches the actual username, group, and service context. Review included files and the order of account modules.

Password policies are ignored

Inspect the active password stack, installed password-quality modules, and distribution-managed settings. A configuration file alone does not activate a module.

Authentication works for one service but not another

Different applications may use different PAM service files and stacks. Inspect the relevant configuration for each service instead of assuming that one change affects every login method.

Linux PAM Configuration Best Practices

Follow these practices when managing authentication on production servers:

  • Back up active configuration files before making changes.
  • Identify the Linux distribution and version first.
  • Understand the complete PAM stack and included files.
  • Use distribution-supported configuration tools when appropriate.
  • Avoid untested module combinations and copied configuration snippets.
  • Test restrictions with a separate, non-privileged account.
  • Keep an administrative session open during testing.
  • Verify that a recovery method is available.
  • Review authentication logs after applying changes.
  • Document each policy and its rollback procedure.
  • Use service-specific controls when they are more suitable than PAM.
  • Recheck authentication behavior after operating system or PAM package updates.

Need a VPS for Linux Server Administration?

Testing PAM rules, troubleshooting authentication failures, and managing Linux access policies are easier when you have a server environment you can configure and control.

ServerNext offers VPS hosting in multiple locations, including the USA, Singapore, Germany, and Bangladesh BDIX. VPS plans include root access, allowing administrators to manage supported operating-system settings and server-level configurations.

Whether you are learning Linux administration, testing authentication policies, or deploying an application, choose a VPS that matches your workload and technical requirements.

Save up to 10% on eligible VPS plans with promo code vNEXT, subject to the current offer terms.

Choose a suitable plan, review the available operating-system options, and apply the promotional code during checkout if eligible.

 

Linux PAM configuration gives system administrators a flexible way to manage authentication, account restrictions, password policies, and session behavior. Understanding module types, control flags, and configuration stacks helps you investigate login problems and implement access policies more safely.

Always back up configuration files, keep an administrative session open, verify recovery access, and test login scenarios with a separate account before deploying changes.

If you need an environment for Linux administration, application deployment, or server-security testing, explore ServerNext VPS hosting and check the available vNEXT promotion.

Official documentation: