Linux Foundation Certified System Security Professional (LFCS-SSP) Intermediate — Quiz 2
Linux Foundation Certified System Security Professional (LFCS-SSP) Intermediate — Quiz 2 — Study Guide
Linux Log Analysis & Auditing
Understanding log analysis and auditing is one of the most critical skills for any system security professional. Logs are your system's "black box recorder" — they capture everything that happens, from successful logins to failed intrusion attempts. When something goes wrong (or when you suspect something *is* going wrong), logs are your first line of investigation. Mastering how to read, search, and monitor them can mean the difference between catching a breach early and missing it entirely.
Log Analysis in Linux
Where Logs Live
Most Linux logs are stored in /var/log/. Each file serves a specific purpose:
| Log File | Purpose |
|---|---|
/var/log/syslog | General system messages (Debian/Ubuntu) |
/var/log/messages | General system messages (RHEL/CentOS) |
/var/log/auth.log | Authentication events (Debian/Ubuntu) |
/var/log/secure | Authentication events (RHEL/CentOS) |
/var/log/kern.log | Kernel messages |
/var/log/dmesg | Boot-time hardware messages |
/var/log/faillog | Failed login attempts |
/var/log/wtmp | Login/logout history (binary format) |
Security Tip: If you suspect unauthorized access,/var/log/auth.log(or/var/log/secure) is your go-to file. It records SSH logins,sudousage, PAM authentication, and more.
Viewing Logs in Real-Time
The most commonly used command for watching logs as they update is tail -f:
# Watch auth.log in real-time
tail -f /var/log/auth.logWatch the last 50 lines, then follow
tail -n 50 -f /var/log/syslogThink of tail -f like watching a live news ticker — it shows you new entries as they appear, without you having to refresh.
Searching and Filtering Logs
Use grep to hunt for specific events:
# Find all failed login attempts
grep "Failed password" /var/log/auth.logFind logins for a specific user
grep "session opened for user john" /var/log/auth.logFind sudo usage
grep "sudo" /var/log/auth.logCombine tools for more powerful analysis:
# Count failed login attempts by IP address
grep "Failed password" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -rnUsing journalctl for systemd Logs
Modern Linux systems using systemd store logs in a binary journal. Use journalctl to query them:
# View all logs
journalctlFollow logs in real-time (like tail -f)
journalctl -fView logs for a specific service
journalctl -u sshdView logs since last boot
journalctl -bFilter by priority (0=emergency to 7=debug)
journalctl -p errThe rsyslog Service
rsyslog is the system logging daemon responsible for collecting, filtering, and routing log messages to the appropriate files. It acts like a central post office — messages from the kernel, applications, and services are sent to rsyslog, which then decides where to deliver them based on rules defined in /etc/rsyslog.conf.
Key capabilities of rsyslog:
# Check rsyslog status
systemctl status rsyslogRestart rsyslog after config changes
systemctl restart rsyslogAuditing with auditd
What is auditd?
The auditd daemon is the Linux Audit System — a powerful framework for tracking security-relevant events at the kernel level. While rsyslog captures application-level messages, auditd goes deeper, monitoring system calls, file access, user actions, and more.
Purpose of auditd:
Key Components
| Component | Role |
|---|---|
auditd | The background daemon that writes audit logs |
auditctl | Command-line tool to manage audit rules |
ausearch | Search the audit log |
aureport | Generate summary reports |
/var/log/audit/audit.log | Where audit events are stored |
Setting Audit Rules with auditctl
# Watch a sensitive file for any access or modification
auditctl -w /etc/passwd -p rwxa -k passwd_changesMonitor a directory for writes and attribute changes
auditctl -w /etc/sudoers.d/ -p wa -k sudoers_changesList current audit rules
auditctl -lDelete all rules
auditctl -DThe -k flag adds a key (label) to the rule, making it easy to search for related events later.
Searching Audit Logs
# Search by key label
ausearch -k passwd_changesSearch by username
ausearch -ua johnSearch for failed events
ausearch --success noGenerate a login report
aureport --loginPersistent Audit Rules
Rules set with auditctl are temporary. To make them permanent, add them to /etc/audit/rules.d/audit.rules:
# /etc/audit/rules.d/audit.rules
-w /etc/passwd -p rwxa -k passwd_changes
-w /etc/shadow -p rwxa -k shadow_changes
-w /etc/sudoers -p wa -k sudoers_changesThen reload:
augenrules --loadPractical Investigation Scenario
You suspect user bob is attempting unauthorized access. Here's your investigation workflow:
# 1. Check recent authentication events
grep "bob" /var/log/auth.log | tail -202. Look for failed sudo attempts
grep "sudo.*bob" /var/log/auth.log3. Check audit log for file access by bob
ausearch -ua bob --success no4. Watch logs in real-time while bob is active
tail -f /var/log/auth.logKey Takeaways
/var/log/auth.log (or /var/log/secure on RHEL) is the most important log for investigating authentication and unauthorized access attempts.tail -f is the standard command for viewing log files in real-time, while journalctl -f serves the same purpose for systemd-managed systems.rsyslog is the central logging service that collects and routes messages from applications and the kernel to appropriate log files.auditd provides deep kernel-level auditing, tracking file access, system calls, and user actions — essential for security investigations and compliance.ausearch to query audit logs by key, user, or success status, and aureport to generate human-readable summaries of audit activity.