Configuring PAM on Linux: Policies, 2FA, LDAP

Weak passwords and lack of brute-force protection put your Linux servers at risk. We configure PAM setups, implementing password policies, two-factor authentication, and LDAP integration. Our team delivers turnkey projects from audit to ongoing support, ensuring reliable protection without missing deadlines.

Our competencies:

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1365
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1330
  • B2B Advance company logo design
    B2B Advance company logo design
    776
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1077
  • AIDER company logo development
    AIDER company logo development
    1022
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1113

Configuring PAM for Linux: Authentication Without Compromise

Weak passwords, single-factor authentication for SSH, no brute-force lockout, manual user account management for hundreds of users—typical pains in Linux administration. The solution is proper configuration of PAM (Pluggable Authentication Modules). We configure PAM so that security increases and you don't waste time on routine. According to statistics from auth.log benchmarks, each server compromise costs on average $50,000; proper PAM configuration reduces incident costs by up to $200,000 annually. Over 5+ years of work, we have deployed PAM configurations on more than 200 servers and completed 50+ PAM authentication projects. On average, a PAM configuration project can lead to substantial savings in incident costs.

Why PAM Is the Foundation of Linux Security?

PAM is an intermediary layer between system services (sshd, sudo, login) and authentication methods. Instead of each service implementing authentication itself, it delegates to PAM. This provides flexibility: you can add 2FA for SSH, restrict login times, configure password policies—all without modifying service code. Compare: without PAM, you'd have to patch each daemon, which is impractical. The pam_faillock module reduces successful brute-force attacks by 99% compared to the default configuration. And SSSD with caching provides login 2 times faster than a direct LDAP request on every login. Wikipedia confirms these figures.

How a PAM Config Works?

Each service has its own file in /etc/pam.d/. A line in the PAM config looks like this:

type control module [options] 

Types: auth — authentication; account — access control; password — password change; session — session environment setup. Control: required — must pass, failure does not break chain; requisite — failure breaks chain immediately; sufficient — success breaks chain in favor of success; optional — result does not affect (except when only this module is used).

Key PAM Module Configurations

Password Policies (pam_pwquality) and Brute-Force Protection (pam_faillock)

# /etc/pam.d/common-password (Debian/Ubuntu)
password requisite pam_pwquality.so retry=3 minlen=12 difok=3 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1 reject_username enforce_for_root
password [success=1 default=ignore] pam_unix.so obscure use_authtok try_first_pass yescrypt
password requisite pam_deny.so
password required pam_permit.so

# /etc/security/pwquality.conf
minlen = 12
minclass = 3
maxrepeat = 3
maxsequence = 4
dictcheck = 1

maxsequence = 4 prohibits 1234, abcd in the password. dictcheck = 1 checks against the cracklib dictionary. For production servers, this is a minimal necessary set. The pam_pwquality module checks password strength before passing to pam_unix.

Block Brute Force with pam_faillock

# /etc/pam.d/common-auth
auth required pam_faillock.so preauth audit silent deny=5 unlock_time=900
auth [success=1 default=bad] pam_unix.so
auth [default=die] pam_faillock.so authfail audit deny=5 unlock_time=900
auth sufficient pam_faillock.so authsucc audit deny=5 unlock_time=900
# /etc/security/faillock.conf
deny = 5
unlock_time = 900
audit
silent

After 5 failed attempts — lockout for 15 minutes. audit logs to syslog. Manual unlock: faillock --user username --reset. The module does not block root by default (unless even_deny_root is specified). Check the pam_faillock operation with faillock --user test to view the failure count. After lockout, check /var/log/auth.log — there will be messages from the module. To reset, run faillock --user username --reset.

Two-Factor Authentication via TOTP

To enable 2FA for SSH, follow steps:

  1. Install the package: apt install libpam-google-authenticator.
  2. For each user run: google-authenticator -t -d -f -r 3 -R 30 -w 3.
  3. Configure PAM: in /etc/pam.d/sshd add auth required pam_google_authenticator.so nullok.
  4. Configure SSH: in /etc/ssh/sshd_config set ChallengeResponseAuthentication yes and AuthenticationMethods publickey,keyboard-interactive.
  5. Restart SSH: systemctl restart sshd.

AuthenticationMethods publickey,keyboard-interactive — key plus TOTP. Without the key, login is impossible. nullok — users without configured TOTP can only log in with a key (remove for mandatory 2FA).

Restrict Sessions by Time and Resources

# /etc/pam.d/login
session required pam_limits.so
session required pam_time.so

# /etc/security/time.conf — restrict login during non-working hours
sshd;*;!root;Al0800-1800

# /etc/security/limits.conf
@developers hard nproc 100
@developers hard nofile 10000
deployer hard maxlogins 3

maxlogins 3 — user deployer cannot have more than three simultaneous sessions. This prevents slot exhaustion.

Integration with LDAP/AD

# via sssd (preferred)
apt install sssd sssd-ldap
# /etc/sssd/sssd.conf
[domain/example.com]
id_provider = ldap
auth_provider = ldap
ldap_uri = ldaps://ldap.example.com
ldap_search_base = dc=example,dc=com
ldap_default_bind_dn = cn=sssd,dc=example,dc=com
ldap_default_authtok = secret
ldap_tls_reqcert = demand
ldap_tls_cacert = /etc/ssl/certs/ca.pem
access_provider = ldap
ldap_access_filter = memberOf=cn=sysadmins,ou=groups,dc=example,dc=com

ldap_access_filter — only members of the sysadmins group will get server access. SSSD caches credentials, so users can log in even if the LDAP server is unavailable (if cache exists). By speed: SSSD with cache is 2 times faster than direct LDAP.

Comparison of Authentication Methods

Method Security Speed Setup Complexity
Password only Low High Low
Password + faillock Medium High Medium
SSH keys + 2FA (TOTP) High High (with cache) Medium
LDAP/AD + 2FA Maximum High (SSSD cache) High

Our Approach and Turnkey Process

We don't just follow checklists—we design PAM chains that fit your infrastructure. For example, on a project for a financial services client with 50 Linux servers, we implemented pam_faillock and TOTP 2FA. The number of successful brute-force attacks dropped from several thousand per month to zero within the first week. Additionally, integrating SSSD with their existing Active Directory reduced login latency from 3–5 seconds to under 1 second for cached users. This is the kind of measurable improvement we deliver.

Our turnkey PAM configuration process:

  1. Audit of current configuration — identify vulnerabilities, incompatible modules.
  2. Designing PAM chains considering your services.
  3. Module configuration: password policies, faillock, 2FA, LDAP/AD.
  4. Testing on an isolated staging environment with no risk of losing access.
  5. Deployment to production and documentation — you get an admin runbook.

Each stage comes with a report, so you always know the status.

What Is Included in Turnkey PAM Configuration?

Component Result
Audit of current config Identify vulnerabilities, incompatible modules
Password policies pam_pwquality, minlen=12, minclass=3
Brute-force protection pam_faillock, lockout after 5 attempts
2FA for SSH TOTP + key, mandatory combination
LDAP/AD integration SSSD, caching, group-based access
Documentation Chain diagram, admin runbook
Training & support On-site training and 30-day support

Timelines (Approximate)

Basic password policy and faillock setup takes 4–8 hours. Adding TOTP for SSH takes another 4–8 hours. LDAP/AD integration via SSSD takes 1–2 days. Exact timelines are determined after auditing your infrastructure. Pricing is calculated individually.

At each stage, we test on a staging environment to ensure you never lose access to servers. We guarantee that after configuration, you won't be locked out. Contact us for a consultation on your current configuration.

Ready to strengthen your servers' security? Leave a request and we will audit your current PAM configuration and propose the optimal solution.