FlashGenius Logo FlashGenius
Linux+ XK0-006 ยท Domain 3 of 5 ยท 18%

Security

PAM ยท LDAP ยท Kerberos ยท Firewalls ยท SELinux ยท AppArmor ยท Cryptography ยท OS Hardening

Security Domain Overview

Linux Security Layers

Security in Linux is built in layers โ€” no single control is sufficient. The standard stack:

  • Authentication โ€” PAM, LDAP, Kerberos, MFA
  • Access Control โ€” DAC (rwx), MAC (SELinux/AppArmor)
  • Network Security โ€” iptables, nftables, UFW, firewalld
  • Cryptography โ€” GPG, TLS/openssl, hashing
  • Compliance โ€” auditd, AIDE, Lynis, CIS Benchmarks

MAC vs DAC

DAC (Discretionary Access Control) โ€” Standard Linux rwx permissions. The file owner controls access. Users can grant or restrict access at their discretion.

MAC (Mandatory Access Control) โ€” SELinux and AppArmor. Policy-controlled by the system/administrator, not by individual owners. Even root is constrained by MAC policy labels and profiles.

Defense in Depth

No single security control is sufficient. The principle of Defense in Depth requires layering multiple independent controls:

  • Authentication (PAM + MFA)
  • Firewall (nftables / firewalld)
  • MAC enforcement (SELinux / AppArmor)
  • Audit logging (auditd)
  • File integrity monitoring (AIDE)
  • OS hardening (SSH config, sudo policy)

If one layer fails, others contain the damage.

XK0-006 New Security Topics

Version 8 (XK0-006) significantly expanded the security domain. Key additions and expansions:

  • LDAP & Kerberos โ€” centralized directory auth, now exam objectives
  • nftables โ€” modern iptables replacement, new emphasis
  • MFA โ€” TOTP, pam_google_authenticator, pam_u2f
  • Compliance scanning โ€” Lynis, AIDE, CIS/STIG
  • SSH MFA โ€” PAM-based MFA for SSH sessions

PAM (Pluggable Authentication Modules)

PAM Fundamentals

PAM provides a flexible framework for authentication on Linux. Configuration files live in /etc/pam.d/ (one file per service, e.g., /etc/pam.d/sshd).

Four module types:

  • auth โ€” Who are you? (verify identity)
  • account โ€” Are you allowed? (account restrictions)
  • password โ€” Password change handling
  • session โ€” Setup/teardown (mount home, logging)

PAM Control Flags

Control flags determine how module success/failure affects the stack:

  • required โ€” Failure counts against final result, but remaining modules still run
  • requisite โ€” Failure causes immediate stop, no further modules run
  • sufficient โ€” Success causes rest of stack to be skipped (if no prior required failures)
  • optional โ€” Result mostly ignored; only matters if it's the only module

Key PAM Modules

  • pam_pwquality โ€” Password complexity (min length, complexity rules)
  • pam_faillock โ€” Account lockout after N failed attempts
  • pam_unix โ€” Standard Unix auth (shadow passwords)
  • pam_google_authenticator โ€” TOTP-based MFA
  • pam_u2f โ€” Hardware token (YubiKey) auth
  • pam_ldap โ€” LDAP authentication
  • pam_krb5 โ€” Kerberos authentication

MFA via PAM

TOTP (Time-based One-Time Password) โ€” generates 6-digit codes that expire every 30 seconds.

  • Install: pam_google_authenticator module
  • Enable MFA for SSH: add to /etc/pam.d/sshd
  • Require ChallengeResponseAuthentication yes in sshd_config
  • pam_u2f โ€” hardware tokens (YubiKey, FIDO2)
  • PAM stack order matters โ€” auth then MFA module

LDAP (Lightweight Directory Access Protocol)

LDAP Fundamentals

LDAP provides centralized user authentication across multiple Linux systems. Instead of local /etc/passwd accounts, users authenticate against a central directory server.

  • ldap:// โ€” unencrypted (port 389)
  • ldaps:// โ€” encrypted TLS (port 636)
  • Config: /etc/ldap.conf or via SSSD
  • Stores: users, groups, passwords, attributes

SSSD (System Security Services Daemon)

SSSD is the modern way to connect Linux to LDAP (and Kerberos/AD). It provides caching for offline authentication.

  • Config: /etc/sssd/sssd.conf
  • Caches credentials for offline use
  • Integrates with PAM and NSS
  • Verify LDAP user: getent passwd username
  • Restart: systemctl restart sssd

Kerberos

Kerberos Concepts

Ticket-based authentication โ€” passwords are never sent over the network after initial login. Uses symmetric key cryptography.

  • KDC (Key Distribution Center) โ€” central auth server
  • TGT (Ticket Granting Ticket) โ€” obtained at login via kinit
  • Service Ticket โ€” obtained by presenting TGT to access a specific service
  • Config: /etc/krb5.conf
  • Realm: Kerberos domain (usually uppercase, e.g., EXAMPLE.COM)

Kerberos Commands

  • kinit username โ€” authenticate and obtain TGT
  • klist โ€” display current tickets and expiry times
  • kdestroy โ€” remove all tickets (logout)
  • klist -l โ€” list credential caches
  • kinit -r 7d username โ€” renewable ticket for 7 days

Ticket flow: kinit โ†’ KDC issues TGT โ†’ present TGT to get service ticket โ†’ access service. No password re-entry needed during ticket lifetime.

Firewall Tools Comparison

Tool Type Use Case Key Commands
iptables Legacy (kernel netfilter) RHEL 7 and earlier, scripting iptables -L, iptables -A INPUT -p tcp --dport 22 -j ACCEPT
nftables Modern replacement for iptables RHEL 8+, Debian 10+, new deployments nft list ruleset, nft add rule ip filter input tcp dport 22 accept
UFW iptables frontend (simple) Ubuntu/Debian, simpler syntax ufw allow 22/tcp, ufw enable, ufw status
firewalld Dynamic zones, iptables/nftables backend RHEL/CentOS/Fedora default firewall-cmd --zone=public --add-port=80/tcp --permanent

firewalld Zones

ZoneBehavior
trustedAll connections accepted โ€” fully trusted network
home / work / internalSelected connections accepted โ€” semi-trusted
publicDefault zone โ€” only explicitly selected services accepted
dmzLimited inbound accepted โ€” demilitarized zone
blockInbound connections rejected (ICMP reply sent)
dropInbound dropped without response โ€” stealth mode

SELinux

SELinux Modes

  • Enforcing โ€” active; violations are denied AND logged
  • Permissive โ€” logs violations but does NOT deny (testing mode)
  • Disabled โ€” completely off (not recommended)

Check: getenforce
Temp change: setenforce 0 (permissive) or setenforce 1 (enforcing)
Permanent: edit /etc/selinux/config โ†’ SELINUX=enforcing (requires reboot)

SELinux Contexts

Every file, process, and port has a security context label.

  • ls -Z /file โ€” show file context
  • ps -eZ โ€” show process context
  • Format: user:role:type:level
  • The type is most important for policy rules
  • Example: httpd_sys_content_t for web content

SELinux Context Tools

  • chcon -t httpd_sys_content_t /var/www/myapp/ โ€” temporary context change (overridden by relabeling)
  • restorecon -Rv /var/www/ โ€” restore to policy default; use after mv/cp
  • semanage fcontext -a -t httpd_sys_content_t '/custom(/.*)?' โ€” create permanent policy rule
  • After semanage fcontext, always run restorecon to apply

Troubleshooting SELinux

  • ausearch -m avc -ts recent โ€” find recent AVC denial messages
  • audit2allow -a โ€” analyze audit log and suggest policy rules
  • sealert โ€” human-readable explanations of denials
  • Log file: /var/log/audit/audit.log
  • Look for avc: denied entries to identify blocked actions

AppArmor

AppArmor Profiles

  • aa-status โ€” show all loaded profiles and modes
  • aa-enforce /path/to/profile โ€” set profile to enforcing mode
  • aa-complain /path/to/profile โ€” log-only / permissive mode
  • aa-disable profile โ€” disable profile
  • Profiles stored in /etc/apparmor.d/
  • Reload profiles: apparmor_parser -r /etc/apparmor.d/profile

AppArmor vs SELinux

  • AppArmor โ€” path-based (controls access by file path). Simpler to configure. Default on Ubuntu and SUSE
  • SELinux โ€” label-based (security context on every object). More granular and powerful. Default on RHEL and Fedora
  • Both implement MAC (Mandatory Access Control)
  • Cannot run both simultaneously on the same system
  • Complain mode (AppArmor) = Permissive mode (SELinux)

OS Hardening

SSH Hardening

Config file: /etc/ssh/sshd_config

  • PermitRootLogin no โ€” block direct root SSH
  • PasswordAuthentication no โ€” key-based auth only
  • AllowUsers alice bob โ€” whitelist specific users
  • Port 2222 โ€” non-default port
  • ClientAliveInterval 300 โ€” disconnect idle sessions
  • MaxAuthTries 3 โ€” limit auth attempts
  • Protocol 2 โ€” SSHv2 only

Apply changes: systemctl reload sshd

sudo Hardening

  • NOPASSWD โ€” allow specific commands without password
  • Cmnd_Alias โ€” group related commands
  • !command โ€” explicitly deny specific command

Example sudoers rule (restrict to one command):

alice ALL=(ALL) /usr/bin/systemctl restart nginx

Edit safely with visudo โ€” validates syntax before saving.

Password Policies (chage)

  • chage -M 90 alice โ€” max days before password expires
  • chage -m 7 alice โ€” min days before password can change
  • chage -W 14 alice โ€” warn days before expiry
  • chage -l alice โ€” list current settings

System-wide defaults in /etc/login.defs:
PASS_MAX_DAYS, PASS_MIN_DAYS, PASS_WARN_AGE

Restricted Shells & Service Accounts

  • usermod -s /sbin/nologin alice โ€” prevent interactive login; used for service accounts
  • usermod -s /bin/false alice โ€” same effect (no shell)
  • /etc/shells โ€” lists valid login shells
  • Service accounts (e.g., www-data, sshd) should always use nologin
  • Unlike locking (passwd -l), nologin still allows PAM/sudo

Cryptography

GPG (GNU Privacy Guard)

  • gpg --gen-key โ€” generate key pair
  • gpg --export -a "alice" > alice.pub โ€” export public key
  • gpg --import alice.pub โ€” import a public key
  • gpg --encrypt -r alice file โ€” encrypt for alice
  • gpg --decrypt file.gpg โ€” decrypt
  • gpg --sign file โ€” sign a file
  • gpg --verify file.sig โ€” verify signature
  • gpg --list-keys โ€” list keyring

Hashing for Integrity

  • sha256sum file โ€” generate SHA-256 hash
  • sha256sum -c checksums.txt โ€” verify from checksum file
  • md5sum โ€” legacy; avoid for security purposes

File integrity baseline workflow:

sha256sum /bin/bash > hash.txt (save baseline)
sha256sum -c hash.txt (verify later โ€” "OK" = no tampering)

openssl Basics

  • openssl genrsa -out key.pem 2048 โ€” generate RSA key
  • openssl req -new -key key.pem -out csr.pem โ€” generate CSR
  • openssl x509 -req -in csr.pem -signkey key.pem -out cert.pem โ€” self-sign
  • openssl s_client -connect host:443 โ€” test TLS connection
  • openssl x509 -in cert.pem -text โ€” inspect certificate details

File Encryption

  • gpg --symmetric file โ€” symmetric encryption with passphrase โ†’ file.gpg
  • openssl enc -aes-256-cbc -in file -out file.enc โ€” encrypt with AES-256
  • openssl enc -d -aes-256-cbc -in file.enc -out file โ€” decrypt

GPG asymmetric = encrypt with recipient's public key, decrypt with their private key. Symmetric = same passphrase to encrypt and decrypt.

Compliance & Auditing

auditd

Linux auditing daemon for tracking system activity and file access.

  • Rules in /etc/audit/audit.rules
  • auditctl -w /etc/passwd -p wa -k passwd_changes โ€” watch file for write/attribute changes
  • -p flags: r=read, w=write, x=execute, a=attribute
  • ausearch -k passwd_changes โ€” search logs by key
  • aureport --summary โ€” summary report
  • Logs: /var/log/audit/audit.log

AIDE (Advanced Intrusion Detection Environment)

File integrity monitoring tool. Detects unauthorized file changes.

  • aide --init โ€” create initial database baseline
  • aide --check โ€” compare current system to database
  • Config: /etc/aide.conf
  • Store database on read-only media for tamper resistance
  • Schedule via cron for regular checks
  • Reports: added, removed, and changed files with attribute details

Vulnerability Scanning & Compliance Tools

  • OpenVAS / Greenbone โ€” full network vulnerability scanner
  • Lynis โ€” security auditing and hardening tool; lynis audit system
  • chkrootkit โ€” rootkit detection
  • rkhunter โ€” rootkit hunter; rkhunter --check
  • CIS Benchmarks โ€” industry-standard hardening guidelines
  • STIG (Security Technical Implementation Guide) โ€” DoD compliance standards

Practice Quiz โ€” 10 Questions

Q1. SELinux is blocking a web server from serving files from a new custom directory /srv/webapp. The audit log shows AVC denials. Which command FIRST restores the correct SELinux context based on the current policy?

Q2. An admin wants to ensure that new firewall rules on a firewalld system survive a reboot. Which flag must be added to firewall-cmd commands?

Q3. In PAM configuration, which control flag causes immediate failure if the module fails, without executing any subsequent modules in the stack?

Q4. An admin needs to prevent the root account from logging in directly via SSH. Which line in /etc/ssh/sshd_config achieves this?

Q5. A sysadmin wants to verify the SHA-256 hash of a downloaded ISO file against a provided checksum. Which command performs this verification?

Q6. Which command temporarily switches SELinux from enforcing to permissive mode WITHOUT requiring a system reboot?

Q7. An AppArmor profile for nginx needs to be loaded in log-only mode (complain mode) for testing without blocking any actions. Which command achieves this?

Q8. In Kerberos authentication, what is the purpose of the TGT (Ticket Granting Ticket)?

Q9. A service account svc_backup should be able to log in and run processes but should not be able to open an interactive login shell. Which command configures this correctly?

Q10. Which tool creates an initial baseline of file checksums and system state for Linux intrusion detection, and can later compare the current system against that baseline?

Memory Hooks โ€” 6 Key Concepts

๐Ÿ”

SELinux Three Modes

"Enforcing=Cop, Permissive=Reporter, Disabled=Vacation"

Enforcing: denies AND logs violations (production). Permissive: only logs, no blocking (safe testing). Disabled: completely off. Check mode: getenforce. Temp change: setenforce 0 (permissive) or setenforce 1. Permanent: /etc/selinux/config (reboot required).

๐Ÿ”ฅ

Firewall Tool Selection

"Ubuntu=UFW, RHEL=firewalld, Old Scripts=iptables, New RHEL8+=nftables"

UFW: simple syntax, Ubuntu/Debian default. firewalld: dynamic zones, RHEL/Fedora default. iptables: legacy, still functional. nftables: modern replacement for iptables on RHEL 8+. Critical: always use --permanent with firewall-cmd then --reload.

๐ŸŽซ

Kerberos Ticket Flow

"kinit gets TGT, TGT gets Service Tickets, klist shows all"

kinit authenticates to KDC and obtains a TGT. Present TGT to get service-specific tickets. No password sent after initial kinit. klist displays all current tickets and their expiry. kdestroy removes all tickets (logout equivalent).

๐Ÿ›ก๏ธ

SSH Hardening Top 4

"No Root, No Password, Allow List, Non-Default Port"

PermitRootLogin no. PasswordAuthentication no. AllowUsers alice bob. Port 2222. All settings live in /etc/ssh/sshd_config. Always run systemctl reload sshd after changes โ€” reload, not restart (keeps existing connections alive).

โœ๏ธ

restorecon vs chcon

"restorecon=Policy Default (persistent), chcon=Manual Override (temporary)"

restorecon -Rv /dir restores context to what the SELinux policy says it SHOULD be. chcon -t type /file manually sets context โ€” overridden by relabeling or restorecon. For permanent rules: use semanage fcontext to define the rule, then restorecon to apply it.

๐Ÿ“‹

auditd Watch Syntax

"-w=Watch path, -p=Permissions to audit, -k=Key for searching"

auditctl -w /etc/passwd -p wa -k passwd_watch. -p flags: r=read, w=write, x=execute, a=attribute change. Search by key: ausearch -k passwd_watch. Summary view: aureport --summary. Logs in /var/log/audit/audit.log.

Flashcards โ€” Click to Flip

SELinux Modes
SELinux: enforcing vs permissive vs disabled โ€” and how to change each
Click to reveal answer
Enforcing: blocks AND logs violations (production use).
Permissive: only logs, no blocking (testing mode).
Disabled: completely off.

Temp change: setenforce 0 (permissive) or setenforce 1 (enforcing) โ€” survives until reboot.

Permanent: edit /etc/selinux/config โ†’ SELINUX=enforcing / permissive / disabled โ€” requires reboot.
firewalld
firewalld: open port 443/tcp permanently and reload
Click to reveal answer
firewall-cmd --zone=public --add-port=443/tcp --permanent
then: firewall-cmd --reload

Without --permanent: rule is lost on reload or reboot.

Check: firewall-cmd --list-all
Remove: firewall-cmd --zone=public --remove-port=443/tcp --permanent
PAM
PAM: four module types and four control flags
Click to reveal answer
Types: auth (who are you?), account (are you allowed?), password (change password), session (setup/teardown).

Control flags:
required โ€” fail counts, stack continues
requisite โ€” fail = immediate stop
sufficient โ€” success = skip rest
optional โ€” result mostly ignored
GPG
GPG: encrypt a file for alice and decrypt it
Click to reveal answer
Encrypt: gpg --encrypt -r alice@example.com file.txt โ†’ file.txt.gpg

Decrypt: gpg --decrypt file.txt.gpg > file.txt

Sign: gpg --sign file.txt
Verify: gpg --verify file.txt.sig
Import key: gpg --import alice.pub
List keys: gpg --list-keys
SELinux Contexts
SELinux context: how to set permanently on a custom web directory
Click to reveal answer
1. semanage fcontext -a -t httpd_sys_content_t '/srv/webapp(/.*)?' โ€” add permanent policy rule.

2. restorecon -Rv /srv/webapp โ€” apply the rule.

Verify: ls -Z /srv/webapp

Just using chcon is temporary โ€” lost on relabeling. restorecon alone only works if policy rule already exists.
SSH Hardening
SSH hardening: 5 key sshd_config settings
Click to reveal answer
PermitRootLogin no โ€” no direct root SSH
PasswordAuthentication no โ€” key-based auth only
AllowUsers alice bob โ€” whitelist specific users
Port 2222 โ€” non-default port
MaxAuthTries 3 โ€” limit auth attempts

After any change: systemctl reload sshd (reload, not restart โ€” keeps existing connections alive)
nftables vs iptables
nftables vs iptables โ€” what's new and the key difference
Click to reveal answer
nftables: modern replacement (RHEL 8+, Debian 10+). Single tool replaces iptables + ip6tables + arptables + ebtables. Faster rule processing.

nft list ruleset โ€” show all rules
nft add rule ip filter input tcp dport 22 accept

iptables: legacy, still works but deprecated in new distros. Use for older systems or existing scripts.
AIDE
AIDE: how to create baseline and check for changes
Click to reveal answer
1. Create baseline: aide --init
2. Activate DB: cp /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
3. Check: aide --check โ€” compare to baseline

Report shows: added, removed, and changed files with attribute details.

Store database on read-only media for tamper resistance. Schedule via cron for regular automated checks.

Study Advisor

Beginner

โ–ผ
Start with SELinux three modes (enforcing/permissive/disabled) and the two key commands (getenforce, setenforce). Learn SSH hardening โ€” specifically PermitRootLogin no and PasswordAuthentication no. Understand the difference between iptables, UFW, and firewalld at a high level before diving into syntax.

Intermediate

โ–ผ
Study PAM module types (auth/account/password/session) and control flags โ€” especially the distinction between required vs requisite. Learn firewalld zones and the critical --permanent flag requirement. Understand the difference between restorecon and chcon for SELinux contexts, and when each is appropriate.

Advanced

โ–ผ
Master Kerberos ticket flow (kinit โ†’ TGT โ†’ service tickets, klist, kdestroy), GPG encryption and signing workflows, auditd watch rules (-w -p -k syntax), AIDE baseline creation and verification, and semanage fcontext for creating permanent SELinux context rules followed by restorecon.

Exam Focus

โ–ผ
High-yield exam topics: SELinux enforcing=block+log, permissive=log only; setenforce 0=permissive; restorecon=restore to policy default; firewall-cmd --permanent is required for persistence; PAM requisite=immediate fail; SSH PermitRootLogin no; nftables=modern iptables replacement (RHEL 8+); /sbin/nologin=no interactive shell for service accounts.

Quick Review

โ–ผ
SELinux: enforcingโ†’permissive=setenforce 0; restorecon -Rv=restore context; chcon=temp.
Firewalld: --permanent + --reload.
UFW: ufw allow 22/tcp + ufw enable.
SSH: PermitRootLogin no / PasswordAuthentication no.
GPG: --encrypt -r / --decrypt.
auditd: -w -p -k syntax; ausearch -k.
AIDE: --init then --check.
Kerberos: kinit / klist / kdestroy.