Kahibaro
Discord Login Register

3.7.2 Authentication policies

Understanding Authentication Policies on Linux

In the context of system security, an authentication policy defines how users prove their identity, under what conditions they are allowed to log in, and how those identities are managed and enforced across different services.

On Linux, authentication is mostly implemented through:

This chapter focuses on configuring and enforcing policies around authentication, not on basic user account concepts or SSH details (covered elsewhere).


Core Building Blocks of Authentication

Local Account Databases

On a typical standalone Linux system, authentication uses:

Each line in /etc/shadow looks like:

username:password_hash:lastchg:min:max:warn:inactive:expire:reserved

Key fields for policy:

You typically modify these via tools instead of editing directly.


PAM (Pluggable Authentication Modules) Overview (Policy Angle)

PAM is the main framework that enforces authentication policies for different services (login, SSH, sudo, graphical logins, etc.).

  auth    required    pam_unix.so
  account required    pam_unix.so
  password requisite  pam_pwquality.so retry=3
  session required    pam_limits.so

Policy tuning is usually done by:

We’ll focus on what kinds of policies you can implement via PAM, not the full PAM architecture.


Password Policy Controls

Global Password Aging with `login.defs`

/etc/login.defs controls default password policies for new accounts and some global login behavior.

Common directives:

Example:

PASS_MAX_DAYS   90
PASS_MIN_DAYS   1
PASS_WARN_AGE   7

This means:

These defaults apply when new users are created (e.g., with useradd), but do not automatically retroactively change existing accounts.


Per-User Password Aging with `chage`

chage configures password aging for individual users.

Common usages:

  sudo chage -l alice
  sudo chage -M 90 alice
  sudo chage -m 1 alice
  sudo chage -W 7 alice
  sudo chage -d 0 alice

Policy approach:

Password Complexity (Quality) Policies

Password strength rules are typically enforced by PAM modules such as:

Config locations vary by distro, but common places are:

An example pam_pwquality line:

password requisite pam_pwquality.so retry=3 minlen=12 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1

Key options (simplified):

Other commonly used options:

Security vs usability:

Password Locking and Disabling Accounts

You can lock accounts to prevent logins without deleting them.

Tools:

Examples:

  sudo passwd -l alice
  sudo passwd -u alice

For system/service accounts that should never be used interactively:

Account Lockout and Login Attempt Limits

To limit brute-force attacks against passwords, you can enforce lockout policies via PAM.

Two commonly used modules (distribution-dependent):

Example Using `pam_faillock` (RHEL/Fedora, Many Modern Systems)

Configuration may be in files like:

Simplified example lines (actual distro syntax may differ):

auth required pam_faillock.so preauth silent audit deny=5 unlock_time=900
auth [success=1 default=bad] pam_unix.so
auth [default=die] pam_faillock.so authfail audit
account required pam_faillock.so

Key options:

Policy points:

Session and Login Restrictions

Authentication policies often include where and when users can log in.

Limiting Logins by Terminal (`/etc/security/access.conf` and `pam_access`)

pam_access.so uses /etc/security/access.conf to restrict logins based on:

PAM line (found in some /etc/pam.d/* files):

account required pam_access.so

/etc/security/access.conf rules look like:

# permission : users/groups : origins
-:root:ALL EXCEPT LOCAL
-:ALL EXCEPT wheel:192.168.1.0/24
+ : ALL : LOCAL

Interpretation (simplified):

Policy use cases:

Controlling Maximum Simultaneous Logins (`/etc/security/limits.conf`)

pam_limits.so reads /etc/security/limits.conf to set resource limits and sometimes max logins per user.

Example entries:

@students   hard   maxlogins   1
@teachers   hard   maxlogins   5

This can prevent account sharing or overuse.

Note: The effect can depend on how sessions are counted (virtual terminals, SSH sessions, graphical logins); behavior may vary between setups.


Time-Based Access Restrictions (Optional Module: `pam_time`)

pam_time.so can limit access based on time of day.

PAM line (in account section):

account required pam_time.so

Rules in /etc/security/time.conf, e.g.:

# services;ttys;users;times
login   tty*    !root   MoFr0800-1800

Very roughly: prevent non-root users from logging in with login outside Monday–Friday 08:00–18:00.

This module is less commonly used but can be relevant in tightly controlled environments.


Centralized Authentication and Policies (Overview-Level)

Beyond local accounts, many organizations want central identity management so that:

Common Linux tools/approaches:

From an authentication policy perspective:

For this course stage, know that:

Multi-Factor Authentication (MFA) Basics on Linux

MFA strengthens authentication policies by requiring something more than just a password, typically:

On Linux, MFA is usually implemented through additional PAM modules, for example:

Typical high-level steps for TOTP-based MFA (example):

  1. Install a TOTP PAM module (libpam-google-authenticator or distro equivalent)
  2. Add a line to relevant PAM services, e.g. /etc/pam.d/sshd:
   auth required pam_google_authenticator.so nullok
  1. Configure SSH or login service to require both password and one-time code
  2. Each user runs a setup tool (like google-authenticator) to generate a secret and QR code, then stores it in an app (e.g., on a phone)

Policy considerations:

Practical Policy Design Considerations

When designing authentication policies on Linux systems, aim for a balance of security and usability:

Document your policies and test changes on a non-critical system before rolling them out widely, especially when editing PAM configs; misconfiguration can lock you out.


Summary

Authentication policies on Linux are implemented using:

Understanding where to set which rule (aging, complexity, lockouts, restrictions, MFA) is the key to building a secure, manageable authentication policy for your Linux systems.

Views: 147

Comments

Please login to add a comment.

Don't have an account? Register now!