Skip to main content

Lesson 5 of 10

Log Analysis & Auditing

Logs are the primary source of truth for incident investigation, compliance, and security monitoring. Knowing where logs live, what they contain, and how to query them efficiently is one of the most practical skills in a security professional's toolkit.

55 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Critical Linux Log Files

Critical Linux Log Files
# Log file locations and their security relevance

/var/log/auth.log         # Authentication events (SSH logins, sudo usage, PAM)
/var/log/syslog           # General system messages
/var/log/kern.log         # Kernel messages (hardware errors, network issues)
/var/log/dpkg.log         # Package installations/removals (detect unauthorized software)
/var/log/ufw.log          # Firewall allow/deny events (detect port scans)
/var/log/apache2/access.log  # Web server requests (scan for SQLi, XSS, traversal)
/var/log/apache2/error.log   # Web server errors (exploit attempts, config errors)
/var/log/nginx/access.log    # Nginx access log
/var/log/mysql/error.log     # Database errors (detect SQLi results)
/var/log/audit/audit.log  # Auditd events (file access, syscalls - most detailed)

# journalctl - systemd journal (most modern Linux systems)
journalctl -u ssh           # SSH service events only
journalctl -u ssh --since "2025-01-01" --until "2025-01-02"
journalctl -f               # Follow live log output
journalctl -p err           # Only error-level messages
journalctl -k               # Kernel messages only

Investigating Suspicious SSH Activity

Investigating Suspicious SSH Activity
# Detect failed SSH login attempts (brute force)
grep "Failed password" /var/log/auth.log | tail -50
# Output: Jan 15 03:22:31 server sshd[12345]: Failed password for root from 185.220.101.47

# Count attempts by source IP
grep "Failed password" /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn
# Output:
# 1247 185.220.101.47   # ← likely brute force from this IP
# 3    192.168.1.50     # ← internal - investigate but less concerning

# Find successful logins after multiple failures (compromised!)
grep "Accepted password" /var/log/auth.log
grep "Accepted publickey" /var/log/auth.log

# Detect new user creation (attacker adding backdoor user)
grep "useradd" /var/log/auth.log
grep "new user" /var/log/auth.log

# Check sudo usage
grep "sudo" /var/log/auth.log
# Suspicious: user not known to use sudo, unusual commands

Auditd - Advanced System Auditing

Auditd - Advanced System Auditing
# Auditd provides kernel-level, tamper-evident logging

# Install and enable
apt install auditd
systemctl enable auditd && systemctl start auditd

# Key audit rules (/etc/audit/audit.rules)
# Monitor /etc/passwd and /etc/shadow for changes
-w /etc/passwd -p wa -k identity
-w /etc/shadow -p wa -k identity

# Monitor sudo configuration changes
-w /etc/sudoers -p wa -k privilege_escalation

# Monitor SSH configuration
-w /etc/ssh/sshd_config -p wa -k sshd_config

# Log all command executions (by UID 1000+)
-a always,exit -F arch=b64 -S execve -F auid>=1000 -k user_commands

# Search audit logs
ausearch -k identity           # Events tagged with 'identity' key
ausearch -k privilege_escalation
ausearch -ui 1000              # All events by user ID 1000
ausearch --start today         # Today's events only
aureport --failed              # Summary of all failed events

Common Mistakes

  • Not enabling auditd on servers handling sensitive data - default logging is insufficient for compliance and incident investigation
  • Sending logs only to the local system - attackers who compromise a system can delete local logs. Always ship logs to a remote SIEM in real-time
  • Not setting log rotation policies - unbounded log growth can fill disk, causing a denial of service (Availability attack)
  • Only looking at raw logs - pattern analysis and correlation across multiple log sources reveals attack chains that are invisible in individual logs

Tip

Tip

Practice Log Analysis Auditing in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).

Practice Task

Note

Practice Task - (1) Write a working example of Log Analysis Auditing from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Log Analysis Auditing is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.

Key Takeaways

  • Logs are the primary source of truth for incident investigation, compliance, and security monitoring.
  • Not enabling auditd on servers handling sensitive data - default logging is insufficient for compliance and incident investigation
  • Sending logs only to the local system - attackers who compromise a system can delete local logs. Always ship logs to a remote SIEM in real-time
  • Not setting log rotation policies - unbounded log growth can fill disk, causing a denial of service (Availability attack)

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done