LINUX-PRODUCTION Contents

Linux Audit and Basic Logging in Production

Implement production-grade logging and audit basics: verify authentication logs, track sudo activity, detect suspicious behavior, and ensure logs survive incidents for real forensic visibility.

On this page

Why Logging Is a Security Control, Not Just Debug Output

If you cannot see what happened, you cannot respond to an incident. Logging is your memory. In production, audit visibility determines whether you detect compromise early or discover it weeks later.

Symptom

  • Security team asks: “Who logged in?” and no answer exists
  • No trace of sudo activity
  • Logs rotated too aggressively and lost
  • After incident, no reliable timeline
  • Authentication failures unnoticed for days

Root Cause

  • Default logging left unverified
  • No centralized log aggregation
  • Auditd not enabled
  • Log retention misconfigured
  • Critical services not logging at all

Investigation

1) Check SSH and Authentication Logs

Debian/Ubuntu:

sudo tail -n 100 /var/log/auth.log

RHEL/CentOS/Alma:

sudo tail -n 100 /var/log/secure

Search failed logins:

sudo grep "Failed password" /var/log/auth.log

2) Inspect systemd Journal

sudo journalctl -xe

Filter SSH logs:

sudo journalctl -u ssh --since "24 hours ago"

Filter sudo activity:

sudo journalctl _COMM=sudo --since "24 hours ago"

3) Verify auditd Status

sudo systemctl status auditd

If not installed:

sudo apt install auditd

Mitigation

1) Ensure Authentication Logging Is Active

Confirm rsyslog or journald is enabled:

sudo systemctl status rsyslog
sudo systemctl status systemd-journald

2) Enable auditd for Critical Monitoring

Example: monitor changes to /etc/passwd:

sudo auditctl -w /etc/passwd -p wa -k passwd_changes

List audit rules:

sudo auditctl -l

Search audit logs:

sudo ausearch -k passwd_changes

3) Configure Log Retention Safely

Check logrotate configuration:

cat /etc/logrotate.conf
ls /etc/logrotate.d/

Ensure logs are rotated but not lost too quickly. Security logs should survive long enough for investigation.

Hardening Strategy

  • Centralize logs (ELK, cloud logging, SIEM)
  • Protect log integrity (restrict write access)
  • Monitor authentication failures
  • Audit privilege escalation attempts
  • Track configuration file changes
  • Define retention policy

Real Incident Pattern

  • Attacker brute-forces SSH
  • Successfully logs in
  • Runs sudo to escalate privileges
  • Creates persistence via cron or systemd unit
  • Deletes or rotates logs to hide activity

If logging is weak, this entire chain becomes invisible.

Verification Checklist

sudo journalctl --disk-usage
sudo auditctl -l
sudo tail -n 50 /var/log/auth.log
  • SSH logins are recorded
  • Sudo usage is visible
  • Audit rules active for critical files
  • Logs are not world-writable

Why This Matters in Real Infrastructure

Security incidents are not prevented by hope — they are detected by visibility. Logging is the foundation of incident response. A production system without reliable audit logs is operating blind.