If you did not log it, it did not happen. Logging and auditing are the foundation of security monitoring, incident response, and compliance. Linux provides multiple logging subsystems, and understanding each one is essential for detecting attacks, investigating incidents, and meeting regulatory requirements.
Modern Linux systems use two primary logging mechanisms: systemd-journald (the binary journal) and rsyslog (the traditional text-based syslog). They work together — journald collects logs and forwards them to rsyslog for persistent storage.
| Log File | Purpose | Security Relevance |
|---|---|---|
| /var/log/auth.log | Authentication events | SSH logins, sudo usage, failed attempts |
| /var/log/syslog | General system messages | Service starts/stops, kernel messages |
| /var/log/kern.log | Kernel messages | Firewall drops, hardware events |
| /var/log/apache2/access.log | Web server requests | Web attacks, scanning activity |
| /var/log/apache2/error.log | Web server errors | Exploit attempts, misconfigurations |
| /var/log/mysql/error.log | Database errors | SQL injection attempts, auth failures |
| /var/log/fail2ban.log | fail2ban actions | Banned IPs, attack patterns |
| /var/log/audit/audit.log | Audit daemon events | File access, system calls, user actions |
| /var/log/wtmp | Login history | Who logged in and when (binary) |
| /var/log/btmp | Failed login history | Failed login attempts (binary) |
journalctl is the primary tool for querying systemd's journal. It provides powerful filtering capabilities that are essential for security analysis.
While syslog captures application-level events, the Linux Audit system (auditd) captures kernel-level events — file access, system calls, and user actions at a much deeper level. This is the gold standard for security auditing on Linux.
💡 The auditd system is required for many compliance frameworks (PCI-DSS, HIPAA, SOC 2). The -k flag assigns a 'key' to each rule, making it easy to search for specific events. Always audit /etc/passwd, /etc/shadow, /etc/sudoers, and SSH config files.
Raw logs are overwhelming. You need to extract meaningful security intelligence from them. Here are practical log analysis techniques:
⚠️ The output above shows 847 failed SSH attempts from 203.0.113.50 — a clear brute-force attack. The 'last' command shows root login attempts from that same IP. This is why fail2ban and key-based authentication are essential. Also note: if you find that log files have been truncated or deleted without log rotation, that is a strong indicator of an attacker covering their tracks.
Attackers who gain access often try to cover their tracks by modifying or deleting log files. Protecting log integrity is a critical defensive measure.
# Make log files append-only (tamper-resistant)
sudo chattr +a /var/log/auth.log
sudo chattr +a /var/log/syslog
# Verify the attribute
lsattr /var/log/auth.log
# Output: ----a-------- /var/log/auth.log
# To remove the attribute (when you need to rotate logs):
sudo chattr -a /var/log/auth.log
# ... perform log rotation ...
sudo chattr +a /var/log/auth.log
# Configure rsyslog to forward to a remote server
# Add to /etc/rsyslog.conf:
*.* @192.168.1.200:514 # UDP forwarding
*.* @@192.168.1.200:514 # TCP forwarding (more reliable)Verify exercises to earn ★ 150 XP and unlock next lab level.