CompTIA Linux+ (XK0-006) · chapter 9 of 14
Month 5: Who are you, and who said so?
In this chapter Objectives 3.1, 3.4
Objective 3.1
PAM and polkit
PAM: one stack for every login
Pluggable Authentication Modules (PAM) let login programs (sshd, sudo, login, su) share one configurable stack instead of each coding its own password checks. Each service has a file in /etc/pam.d/. Lines have a type (auth proves identity, account checks if login is allowed now, password handles changes, session sets things up), a control flag and a module.
# /etc/pam.d/password-auth (excerpt) auth required pam_env.so auth required pam_faillock.so preauth auth sufficient pam_unix.so account required pam_unix.so password requisite pam_pwquality.so session required pam_limits.so
Exam tip RHEL shares system-auth and password-auth (managed by authselect). Debian shares common-auth, common-password...
Control flags
required: must pass, but the stack keeps going (so attackers can't tell which module failed). requisite: must pass, and failure stops right away. sufficient: success is enough on its own if nothing required failed before it. optional: only matters if it's the only module. Useful modules: pam_unix (local passwords), pam_faillock (lockouts), pam_pwquality (strength), pam_limits (limits.conf).
Exam tip Editing PAM? Keep a root shell open in another window until you've tested a new login.
Polkit: permission for privileged actions
Polkit decides whether an unprivileged process may ask a privileged system service to do something over D-Bus: reboot, mount a disk, manage a unit, change the network. It's the reason a desktop user can shut down without sudo, and the prompt behind pkexec. Rules live in /etc/polkit-1/rules.d/ (written in JavaScript).
Sam: PAM asks 'are you really Rosa?' Polkit asks 'may Rosa do this one thing?'
Exam tip sudo = run a command as root. polkit = may this user ask that service for this action?
Objective 3.1
Central identity: LDAP, Kerberos, SSSD, Samba
LDAP and Kerberos
LDAP is the protocol for directories: a tree of entries such as uid=sam,ou=people,dc=kibbleco,dc=example, holding users, groups and attributes (port 389, or 636 for LDAPS). Kerberos handles authentication with tickets: you prove your password once to the KDC, get a ticket-granting ticket (kinit, klist), and then log in to other services without sending the password again. That's single sign-on.
Exam tip Kerberos fails when clocks differ by more than about 5 minutes. Check time sync first.
SSSD, Winbind and realm
SSSD (System Security Services Daemon) connects Linux to central identity: Active Directory, FreeIPA or plain LDAP plus Kerberos. It caches credentials, so people can still log in if the directory is briefly down. realm join kibbleco.example (realmd) discovers the domain and sets up SSSD in one step. Winbind, from Samba, is the older alternative for joining Active Directory.
$ sudo realm join kibbleco.example -U admin $ id sam@kibbleco.example $ realm list
Samba
Samba speaks SMB, Windows' file and print sharing protocol. It shares Linux directories to Windows clients (smb.conf), mounts Windows shares on Linux, and can even act as an Active Directory domain controller. Its Winbind piece maps Windows users and groups to Linux IDs.
Exam tip Samba = SMB service. SSSD = identity. Both can talk to Active Directory, for different jobs.
Check yourself 1Kibble joins db01 to its Active Directory domain. Staff log in with AD accounts, and logins must keep working for a while if a domain controller is unreachable. Which component does this?
- Polkit rules in /etc/polkit-1/rules.d
- SSSD, set up with realm join
- pam_faillock in the sshd stack
- An rsyslog forwarding rule
Show the answer
Answer: B. SSSD, set up with realm join
SSSD talks to AD (LDAP and Kerberos underneath) and caches credentials for offline logins. realm join configures it for you.
Objective 3.1
Logging and auditing
The journal and rsyslog
journalctl reads systemd's journal: -u sshd (one unit), -b (this boot), -p err (errors and worse), --since "1 hour ago", -f (follow), -k (kernel). Make it survive reboots with Storage=persistent (or by creating /var/log/journal). rsyslog writes classic text logs under /var/log using facility.priority rules, and can forward to a central server.
# /etc/rsyslog.d/50-central.conf authpriv.* /var/log/secure *.* @@logs.kibbleco.example:514
Exam tip Login events: /var/log/auth.log on Debian/Ubuntu, /var/log/secure on RHEL. @@ forwards over TCP, @ over UDP.
logrotate
logrotate keeps logs from filling the disk: it renames the current log, starts a fresh one, compresses old ones and deletes the oldest. Global defaults in /etc/logrotate.conf, per-app rules in /etc/logrotate.d/. It runs daily from a timer or cron.
/var/log/labeld/*.log {
weekly
rotate 8
compress
missingok
postrotate
systemctl reload label-print
endscript
}Exam tip postrotate tells the app to reopen its log, or it keeps writing to the renamed file.
auditd
The Linux audit system records kernel events: file access, system calls, logins, command execution. auditd writes them to /var/log/audit/audit.log. Persistent rules go in /etc/audit/rules.d/*.rules (augenrules merges them into audit.rules). -w watches a path, -p picks r/w/x/a (attribute change), -k tags it so you can search later with ausearch -k; aureport summarizes.
-w /etc/shadow -p rwa -k shadow -w /etc/sudoers -p wa -k sudoers $ sudo ausearch -k shadow -i
Exam tip auditctl -l lists the loaded rules. Rules added with auditctl alone vanish at reboot.
Check yourself 2Priya wants a record every time anyone changes /etc/sudoers, searchable later. Which rule fits?
- A logrotate rule for /etc/sudoers
- authpriv.* /var/log/sudoers in rsyslog
- auditctl -w /etc/sudoers -p r
- An audit rule: -w /etc/sudoers -p wa -k sudoers
Show the answer
Answer: D. An audit rule: -w /etc/sudoers -p wa -k sudoers
An audit watch with w (write) and a (attribute change), tagged with -k, catches every change. Put it in /etc/audit/rules.d so it loads at boot; search it with ausearch -k sudoers.
Objective 3.4
Account hardening
Password policy that helps
Length beats complexity: a long passphrase is stronger and easier to remember than P@ssw0rd!. Set rules with pam_pwquality (/etc/security/pwquality.conf: minlen, dictionary checks). History/reuse: pam_pwhistory remember=5 blocks the last five. Expiration: chage -M sets a maximum age. Current guidance (NIST) avoids routine forced changes, and forces one when a password may be compromised.
# /etc/security/pwquality.conf minlen = 14 dictcheck = 1 usercheck = 1
Exam tip Exam wording: complexity, length, expiration, reuse, history. Know what sets each one.
MFA and breach lists
Multifactor authentication (MFA) combines factors: something you know (password), have (phone app, hardware key) or are (fingerprint). For SSH: keys plus a TOTP code through a PAM module, or a FIDO2 hardware key (ed25519-sk). Checking existing breach lists: reject passwords that already appear in known breach collections, because attackers try those first.
Exam tip A password from a breach list is weak no matter how complex it looks.
Lockouts: pam_tally2 and pam_faillock
pam_tally2 counted failed logins and locked accounts on older distros. It's been removed; today's module is pam_faillock (settings in /etc/security/faillock.conf: deny=, unlock_time=). faillock --user rosa shows the failures; faillock --user rosa --reset unlocks her.
Exam tip The objectives still list pam_tally2. Know it's the old one, replaced by pam_faillock.
Restricted shells and not being root
Service accounts get /sbin/nologin (or /usr/sbin/nologin) as their shell: login is refused with a polite message. /bin/rbash (restricted bash) allows a login but blocks cd, changing PATH, commands containing / and output redirection: useful for a kiosk-style account. Avoid running as root: log in as yourself and use sudo per command, run services as their own accounts, and lock or restrict direct root login.
Exam tip nologin = no interactive login at all. rbash = a login, with a short leash.
Go deeper
More on the objectives in this chapter, in the same exam-ready detail.
Objective 3.1 · Logging: journalctl, rsyslog, logrotate, /var/log
Logs: journald, rsyslog, logrotate
journald and journalctl
systemd's journal collects logs from services and the kernel.
- journalctl -u sshd: one service
- journalctl -f: follow live
- journalctl -b (this boot), -b -1 (previous boot)
- journalctl -p err: errors and worse
- journalctl --since '1 hour ago'
- Make it persistent across reboots: create /var/log/journal (or Storage=persistent in /etc/systemd/journald.conf)
rsyslog, /var/log and logrotate
rsyslog writes classic text logs and can forward to a central server (rules in /etc/rsyslog.conf, /etc/rsyslog.d/). Common files: /var/log/messages (RHEL) or /var/log/syslog (Debian), /var/log/secure or auth.log (logins), dmesg/kern logs. logrotate rotates, compresses and deletes old logs on a schedule (/etc/logrotate.conf, /etc/logrotate.d/).
Exam tip Disk filling with logs: check logrotate settings and journald's SystemMaxUse.
Objective 3.1 · System audit: audit.rules, auditd
The Linux audit system: auditd
What it records
auditd records security-relevant events from the kernel: who changed a file, who ran a command, failed access, system calls. Logs go to /var/log/audit/audit.log.
- Rules: **/etc/audit/rules.d/*.rules** (compiled into audit.rules by augenrules)
- auditctl -w /etc/passwd -p wa -k identity: watch writes/attribute changes
- auditctl -l: list rules
- ausearch -k identity, aureport --login: search and report
Objective 3.4 · Passwords: complexity, length, expiration, reuse, history
Password policy
Where it's set
Password rules are spread across a few files and PAM modules:
- Complexity and length: pam_pwquality in /etc/security/pwquality.conf (minlen=14, minclass, dcredit, ucredit...)
- Expiration: /etc/login.defs (PASS_MAX_DAYS) and chage per user
- Reuse/history: pam_pwhistory (remember=5) so users can't cycle old passwords
- Lockout after failures: pam_faillock (deny=5, unlock_time)
Modern guidance
Current NIST guidance favors long passphrases and checking against breached-password lists over frequent forced changes and odd character rules; many organizations still require expiration, and the exam expects you to know both settings.
Objective 3.4 · Checking existing breach lists
Checking passwords against breach lists
Why
Passwords that appeared in previous data breaches are tried first by attackers (credential stuffing and dictionary attacks). Policies should reject them even if they meet complexity rules.
- Services such as Have I Been Pwned offer a k-anonymity API (only a hash prefix is sent)
- pam_pwquality's dictionary check (cracklib) rejects common words
- Password managers and identity providers often check breach lists automatically
Objective 3.4 · Restricted shells: /sbin/nologin, /bin/rbash
nologin and restricted bash
Two tools
/sbin/nologin (or /usr/sbin/nologin) as an account's shell refuses interactive logins with a polite message; use it for service accounts and SFTP-only users. /bin/rbash (restricted bash) allows a login but blocks cd, changing PATH, running commands with a /, and output redirection, so users can run only what you put in their PATH.
Exam tip rbash is easy to escape if the user can run editors or interpreters; it's a speed bump, not a sandbox.
Practice questions
Answer in your head, then open the answer. Ranger's Terminal has 514 questions like these for Linux+, with mock exams.
Question 1On a Kibble & Co. workstation, a non-root user clicks to mount a USB drive and a dialog asks for an admin password. Which framework decides whether that unprivileged desktop app may perform the privileged action?
- Polkit
- fail2ban
- sudo
- SELinux
Show the answer
Answer: A. Polkit
Polkit (PolicyKit) lets unprivileged processes ask a privileged service over D-Bus to do something, and its rules decide yes, no or 'ask for admin authentication'. sudo is for whole commands typed in a shell, not desktop requests.
Question 2Priya is reading /etc/pam.d/sshd on web01. One auth line uses the control flag requisite, and that module fails. What happens to the login attempt?
- PAM ignores the result unless it is the only module in the stack
- PAM runs the remaining modules and then reports a failure
- PAM treats the login as successful if an earlier module passed
- PAM fails the login at once and skips the later modules
Show the answer
Answer: D. PAM fails the login at once and skips the later modules
A failing 'requisite' module ends the stack immediately with failure. A failing 'required' module also fails the login, but PAM keeps running the other modules first so an attacker cannot tell which one failed.
Question 3Sam wants an extra PAM module to run only for SSH logins on db01, not for console or sudo. Which file should he edit?
- /etc/nsswitch.conf
- /etc/pam.d/sshd
- /etc/ssh/sshd_config
- /etc/security/limits.conf
Show the answer
Answer: B. /etc/pam.d/sshd
Each PAM-aware service reads its own stack from /etc/pam.d/<service>, so /etc/pam.d/sshd affects only SSH. sshd_config's UsePAM yes merely tells sshd to use that stack.
Question 4Kibble & Co. wants its new Linux file server to accept Active Directory accounts. The team wants one command that discovers the domain, joins it and writes the SSSD, NSS and PAM settings for them. Which command fits?
- ldapsearch -x -b dc=kibbleco,dc=example
- smbclient -L //dc01.kibbleco.example
- realm join kibbleco.example -U admin
- kinit admin@KIBBLECO.EXAMPLE
Show the answer
Answer: C. realm join kibbleco.example -U admin
realmd's 'realm join' discovers the domain, creates the computer account, and configures SSSD (by default) plus the NSS and PAM pieces. kinit is a later step a user runs to get a ticket.
Question 5After a VM was restored from a snapshot, every Kerberos login to the AD domain fails and the logs show 'Clock skew too great'. What is the BEST fix?
- Sync the clock with chronyd against the domain's NTP server
- Rejoin the server to the domain with realm leave and realm join
- Delete and recreate the user's Kerberos principal
- Raise the ticket lifetime in /etc/krb5.conf to 24 hours
Show the answer
Answer: A. Sync the clock with chronyd against the domain's NTP server
Kerberos rejects requests when client and KDC clocks differ by more than the allowed skew (5 minutes by default). A restored snapshot often has an old clock; fixing time sync with chrony/NTP fixes the logins.
CompTIA, A+, Network+, Security+ and Linux+ are trademarks of CompTIA, Inc. Ranger Gamez is not affiliated with or endorsed by CompTIA. The practice questions are written to the published exam objectives; they are not real exam questions.