Audit Logs — Monitoring Security Events in Linux¶
Audit Logs provide a detailed record of security-related events occurring on a Linux system. They help administrators track user activity, monitor system changes, investigate security incidents, detect unauthorized access, and meet compliance requirements. Linux provides several logging and auditing mechanisms, including system logs, systemd journal, and the Linux Audit Framework (
auditd). Every Linux administrator, DevOps engineer, Cloud Architect, Platform Engineer, and Site Reliability Engineer (SRE) should understand how to collect, analyze, and manage audit logs in production environments.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand Linux auditing
- Learn the Linux Audit Framework
- Install and manage
auditd - Create audit rules
- Search audit logs
- Investigate security events
- Monitor critical files
- Apply production auditing best practices
Prerequisites¶
Complete:
- Modules 1–10
- Module 11 Lessons 1–6
Why Learn Audit Logs?¶
Imagine a critical configuration file changes unexpectedly.
Without auditing:
With auditing:
Audit logs help identify who, what, when, and how an event occurred.
What is Linux Auditing?¶
Linux auditing records security-related events, including:
- User logins
- Authentication failures
- File access
- File modifications
- Command execution
- Permission changes
- System configuration changes
Audit logs support:
- Security investigations
- Compliance
- Troubleshooting
- Incident response
Linux Logging Components¶
Linux systems commonly use:
For security auditing:
What is auditd?¶
auditd is the Linux Audit Daemon.
Responsibilities include:
- Recording security events
- Monitoring important files
- Logging system calls
- Detecting policy violations
Install auditd¶
Ubuntu/Debian:
RHEL/Rocky/AlmaLinux:
Start the Audit Service¶
Check status.
Audit Log Location¶
Most Linux distributions store audit logs in:
View Audit Logs¶
Display the log.
Monitor the log.
Search Audit Logs¶
Use:
Example:
Search authentication failures.
Generate Audit Reports¶
Use:
Summary report.
Authentication report.
Login report.
File report.
Add an Audit Rule¶
Monitor a file.
Meaning:
-w→ Watch file-p w→ Monitor writes-p a→ Monitor attribute changes
Combined:
Add a Rule with a Key¶
Search by key.
List Active Rules¶
Delete a Rule¶
Persistent Rules¶
Temporary rules disappear after reboot.
Persistent rules are commonly stored in:
After updating rules, restart the service.
Monitor Failed Logins¶
Search:
Monitor File Changes¶
Example:
Monitor Command Execution¶
Example:
Using journalctl¶
View security-related journal entries.
View SSH logs.
or
(depending on the Linux distribution)
Common Commands¶
View audit log.
Search events.
Generate reports.
List rules.
Add rule.
Real Production Examples¶
Monitor password database.
Search login events.
Generate authentication report.
Monitor SSH service logs.
Production Perspective¶
Audit logging is essential for:
- Security investigations
- Compliance (PCI DSS, HIPAA, ISO 27001, SOC 2)
- Incident response
- Insider threat detection
- Forensic analysis
- Enterprise monitoring
- Government environments
- Financial institutions
Many compliance frameworks require security auditing and log retention.
Hands-on Lab¶
Task 1¶
Install auditd.
Task 2¶
Start the service.
Task 3¶
Check service status.
Task 4¶
List current audit rules.
Task 5¶
Monitor /etc/passwd.
Task 6¶
Modify /etc/passwd (in a test environment) or inspect existing events, then search the audit log.
Task 7¶
Generate an authentication report.
Task 8¶
Monitor the audit log in real time.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
auditctl | Manage audit rules | Security monitoring |
ausearch | Search audit logs | Incident investigation |
aureport | Generate audit reports | Compliance reporting |
journalctl | View system logs | Troubleshooting |
tail -f | Monitor logs live | Security operations |
systemctl status auditd | Verify audit service | Health checks |
Common Audit Mistakes¶
| Mistake | Solution |
|---|---|
Not running auditd | Enable and start the service |
| Monitoring too few files | Audit critical system files |
| Creating only temporary rules | Store persistent rules |
| Never reviewing logs | Schedule regular audits |
| Ignoring audit storage | Monitor disk usage and log retention |
Production Troubleshooting Scenario¶
Scenario
An administrator discovers that /etc/passwd was modified.
Without auditing:
With auditing:
The audit log identifies:
- User
- Process
- Timestamp
- Command
- Result
The security team can investigate the incident quickly and accurately.
Best Practices¶
- Enable
auditdon production systems. - Audit critical system files and directories.
- Create persistent audit rules.
- Review audit logs regularly.
- Protect audit logs from unauthorized modification.
- Synchronize system time using NTP or Chrony for accurate timestamps.
- Archive and retain logs according to organizational policies.
- Forward audit logs to a centralized logging or SIEM platform for long-term analysis.
Common Mistakes¶
❌ Disabling auditing to save resources.
✅ Avoid disabling auditing to save resources; fix the configuration instead.
❌ Monitoring too few security events.
✅ Avoid this mistake: monitoring too few security events.
❌ Ignoring authentication failures.
✅ Always review authentication failures.
❌ Allowing audit logs to grow without retention planning.
✅ Do not allow audit logs to grow without retention planning.
❌ Never reviewing audit reports.
✅ Always reviewing audit reports.
Interview Questions¶
Beginner¶
- What is Linux auditing?
- What is
auditd? - Where are audit logs stored?
- Which command searches audit logs?
Intermediate¶
- What is the difference between
ausearchandaureport? - How do you monitor changes to
/etc/passwd? - Why should audit rules be persistent?
- What information is typically recorded in an audit log?
Architect Level¶
- How would you design centralized audit logging for hundreds of Linux servers?
- How would you use audit logs during a security incident investigation?
- What auditing controls would you implement to satisfy compliance requirements?
Summary¶
In this lesson, you learned:
- Linux auditing fundamentals
- The Linux Audit Framework
- Managing
auditd - Creating audit rules
- Searching audit logs
- Generating audit reports
- Monitoring critical files
- Production auditing best practices
Audit logging provides detailed visibility into system activity and is a critical component of Linux security. By recording security events, monitoring sensitive files, and generating reports, audit logs support incident response, compliance, troubleshooting, and forensic investigations.
Key Takeaways¶
auditdrecords security-related events on Linux.- Use
auditctlto create audit rules. - Use
ausearchto investigate specific events. - Use
aureportto generate audit summaries. - Monitor critical files such as
/etc/passwd. - Protect, retain, and regularly review audit logs as part of your security operations.
What's Next?¶
Security Updates — Keeping Linux Systems Protected
You'll explore:
- Why security updates are important
- Updating installed packages
- Checking for security advisories
- Automatic security updates
- Kernel updates
- Reboot requirements
- Production patch management best practices
By the end of the lesson, you'll be able to keep Linux systems secure by applying security patches safely, managing updates effectively, and maintaining a structured patch management process for production environments.