Logs and auditing are critical components of Linux security. They help system administrators and cybersecurity professionals monitor system activity, detect anomalies, and investigate security incidents. This module covers how to work with logs and perform basic system auditing.
Linux maintains logs to record system events, application activity, and security-related actions.
| Log File | Purpose |
|---|---|
/var/log/syslog |
General system messages |
/var/log/auth.log |
Authentication attempts and sudo usage |
/var/log/kern.log |
Kernel events |
/var/log/dmesg |
Boot-time messages |
/var/log/faillog |
Failed login attempts |
/var/log/secure |
Security events (Red Hat-based systems) |
Why logs matter for cybersecurity:
journalctlModern Linux systems using systemd store logs in a binary journal accessible via journalctl.
View all logs:
sudo journalctl
View logs in real-time:
sudo journalctl -f
View logs for a specific service (e.g., SSH):
sudo journalctl -u ssh
View logs from the current boot:
sudo journalctl -b
Tracking login activity is essential for detecting unauthorized access attempts.
sudo cat /var/log/auth.log
Common commands for login monitoring:
last
sudo faillog -a
who
Cybersecurity professionals look for anomalies or unusual behavior in logs:
sudo grep "Failed password" /var/log/auth.log
sudo grep "sudo" /var/log/auth.log
watch:watch -n 10 'sudo tail -n 20 /var/log/auth.log'
This command updates the last 20 lines of the log every 10 seconds, providing near real-time monitoring.
Students should now understand:
journalctl and traditional log files