Skip to main content
Linux Fundamentals Recap: ACLs, PAM & SSH Hardening
Lesson 1 of 12

Linux Fundamentals Recap: ACLs, PAM & SSH Hardening

Review Linux file permissions and POSIX ACLs, interpret PAM authentication stacks, and harden an OpenSSH server without locking yourself out.

Intermediate 26 min Linux & Windows
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Audit standard UNIX permissions, special bits (SUID, SGID, sticky), and POSIX ACL masks on files and directories
  • Explain how PAM module types and control flags evaluate an authentication request
  • Configure hardened OpenSSH server settings and verify syntax safely before reloading
  • Diagnose common permission and configuration traps that break key-based SSH login

#Why this matters

Every Linux server starts with three access boundaries: file permissions, login authentication, and remote shell configuration. Misconfigured permissions leak secrets or enable local privilege escalation, while weak authentication or exposed SSH settings invite automated brute-forcing within minutes of deployment.

Hardening these layers requires precision because a small mistake in POSIX ACLs, Pluggable Authentication Modules (PAM), or /etc/ssh/sshd_config can silently break services or lock administrators out of a remote machine.

#Standard permissions, special bits, and POSIX ACLs

Standard POSIX permissions divide access into owner (u), owning group (g), and others (o), with read (4), write (2), and execute (1) bits. Three special bits add targeted behaviour:

Bit Octal Effect on files Effect on directories
SUID 4000 Process runs with file owner's EUID Ignored on Linux
SGID 2000 Process runs with file group's EGID New items inherit directory's group
Sticky 1000 Ignored on modern Linux Only owner or root can delete or rename items

When a single owning group is too coarse, POSIX Access Control Lists (ACLs) grant permissions to specific users or secondary groups without making a file world-readable. A trailing + in ls -l (for example -rw-r-----+) signals an extended ACL.

Inspecting and adjusting POSIX ACLs on a lab directory
$ sudo setfacl -m u:auditor:rx /srv/reports
$ sudo setfacl -m d:u:auditor:rx /srv/reports
$ getfacl /srv/reports
# file: srv/reports
# owner: root
# group: ops
user::rwx
user:auditor:r-x
group::r-x
mask::r-x
other::---
default:user::rwx
default:user:auditor:r-x
default:group::r-x
default:mask::r-x
default:other::---

Watch the mask:: entry closely. On a file with an ACL, the group bits shown by ls -l represent the ACL mask, not the owning group alone. If you run chmod g-x on that file, you shrink the mask and silently strip execute permission from auditor as well (which getfacl flags with #effective:r--). To remove an ACL cleanly, use setfacl -x u:auditor /srv/reports or setfacl -b to strip all extended entries.

#How PAM evaluates logins

PAM separates authentication logic from services like sshd, login, and sudo. Each service has a configuration file under /etc/pam.d/ made of lines with four fields:

  1. module_typecontrol_flag | module_path | module_arguments

PAM splits rules into four management groups:

  • auth: verifies identity (passwords, hardware keys, or lockout counters via pam_faillock.so).
  • account: checks account validity (expiry, locked status, allowed hosts, pam_nologin.so).
  • password: handles credential updates and complexity (pam_pwquality.so).
  • session: sets up and tears down sessions (pam_limits.so, home directories, login logs).

Control flags decide how each result affects the stack:

  • required: must pass, but PAM runs remaining modules of that type before failing (hiding which check failed).
  • requisite: must pass, and aborts the stack immediately on failure.
  • sufficient: if it passes and no earlier required failed, succeeds immediately; failure is non-fatal.
  • optional: matters only when no other module of that type returns a result.

#Hardening OpenSSH safely

OpenSSH reads /etc/ssh/sshd_config (and drop-in files under /etc/ssh/sshd_config.d/*.conf, where earlier directives take precedence). A strong baseline eliminates password brute-forcing, blocks direct root login, and restricts who may connect:

ini
# /etc/ssh/sshd_config.d/99-hardening.conf
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
UsePAM yes
AllowGroups sshusers
MaxAuthTries 3
X11Forwarding no
AllowAgentForwarding no

Keeping UsePAM yes while PasswordAuthentication no is set ensures PAM account and session modules (account expiration, nologin, resource limits) still run for key-based logins.

Safe SSH hardening rolloutSafe SSH hardening rolloutAdminServerKeep existing root/sudo shell openWrite 99-hardening.conf and run sshd -tExit 0 (syntax valid)Reload sshd serviceOpen second terminal and test key loginLogin succeeds; old session can now close

Before disabling password logins, confirm your Ed25519 key works and verify permissions under StrictModes yes (the default). If ~/.ssh is not 700 or ~/.ssh/authorized_keys is writable by group or others (for instance 664), sshd silently ignores the key and falls back or rejects the login.

#Common mistakes

  • Disabling passwords before testing keys: confirm key login in a second terminal while keeping an admin shell open.
  • Ignoring sshd_config.d precedence: OpenSSH applies the first matching directive, so an early drop-in file overrides settings appended to sshd_config.
  • Loose .ssh permissions: ssh rejects private keys looser than 0600, and sshd (StrictModes yes) rejects authorized_keys if group or others can write ~, ~/.ssh, or authorized_keys.
  • Editing /etc/pam.d/ without a backup: a syntax error in common-auth or system-auth can break sudo and sshd together.

#Summary

Standard UNIX bits (rwx, SUID, SGID, sticky) handle basic ownership, while POSIX ACLs add per-user rules capped by the ACL mask. PAM evaluates logins across auth, account, password, and session stacks using control flags such as required, requisite, and sufficient. Hardened OpenSSH disables root and password logins while keeping UsePAM yes, enforcing StrictModes yes, and verifying syntax with sshd -t before closing an active shell.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge