Sub topic 13
PAM, Password Policy, and Sudo
Assume you can use sudo, edit text files, and inspect systemd logs. You should also understand users, groups, file permissions, and SSH. Test these changes on a virtual machine before applying them to a production server.
How PAM controls access
PAM, the Pluggable Authentication Modules framework, is a set of shared libraries that applications use for authentication and account checks. SSH, login, sudo, and display managers can use different PAM service files under /etc/pam.d/.
A PAM stack usually contains these module types:
auth: verifies identity, such as a password or SSH key.account: checks whether the account may log in.password: changes passwords and checks their quality.session: performs work when a session starts or ends.
The order of modules matters. A module can reject the request, record a failure, or pass control to the next module. On systems managed by authselect, edit the selected profile instead of making unsupported manual changes to generated files.
Set password and account policy
Password quality is commonly configured through /etc/security/pwquality.conf. The exact CIS values depend on the benchmark and profile. A longer password requirement is usually preferable to complicated character rules.
# /etc/security/pwquality.conf
minlen = 14
difok = 4
minclass = 4
retry = 3Password aging is separate from password quality. The following example applies aging to a local user, then displays the result:
sudo chage -M 90 -m 1 -W 14 alice
sudo chage -l aliceDo not apply short expiration periods blindly. Service accounts, emergency accounts, and accounts using only SSH keys may need documented exceptions. Also check that the active PAM profile actually calls pam_pwquality and pam_faillock; changing a configuration file that is not in the active stack has no effect.
Configure sudo safely
sudo lets an approved user run a command with another user's privileges. Store local rules in /etc/sudoers.d/ and validate them with visudo. Never edit the file with a normal editor without validation.
For example, this rule grants full administrative access only to members of a named group and records sudo commands:
# /etc/sudoers.d/90-linux-admins
%linux-admins ALL=(ALL:ALL) ALL
Defaults use_pty
Defaults logfile="/var/log/sudo.log"Validate the file and inspect the effective permissions:
sudo visudo -cf /etc/sudoers.d/90-linux-admins
sudo -l -U alicePrefer specific commands over unrestricted access when the job allows it. Remember that command arguments, writable scripts, and environment variables can turn an apparently narrow rule into full root access. Use sudo -l to test as the intended user, and review both successful and failed events in the system journal or configured sudo log.
Exercise
Why should you use visudo when creating a sudoers.d file?
Show answer
visudo checks the syntax before sudo uses the rule, reducing the risk that a typo disables administrative access or creates an unintended permission.