Kahibaro
Discord Login Register

4.6 Logging and Auditing

Why Logging and Auditing Matter

Linux gives you enormous power—but with power comes responsibility. Logging and auditing are how you answer questions like:

In this chapter, you’ll learn how Linux records system activity, how to read those records efficiently, and how to design a logging/auditing strategy that is useful in real-world operations, troubleshooting, and security.

Systemd’s journalctl and traditional syslog files (e.g. in /var/log) are covered in other chapters; here we look at how to think about logging holistically and how to tie logs and auditing together as an advanced skill.


Types of Events You Should Log

Before focusing on tools, decide what kinds of events you care about. Typical categories:

You won’t log everything forever; instead, decide:

Core Logging Architecture Concepts

Linux logging is usually built from a few core building blocks:

Important design principle:

Logging and auditing become powerful when you centralize and correlate logs from many sources.

Designing a Logging Strategy

Instead of simply “turning on everything”, design your logging with intent.

1. Define Goals

Common goals:

Each goal implies different retention, detail level, and alerting.

2. Decide on Log Levels

Log messages typically use levels such as:

Guidelines:

3. Retention and Rotation

Logs grow quickly. You need a policy:

Balance cost vs. usefulness: old logs that nobody can query are not helpful.

4. Centralization

For anything beyond a few servers, centralize logs:

Centralization enables:

Auditing vs Logging

Logging and auditing overlap but are not identical:

On Linux, auditing typically means:

You’ll usually use:

Common Events to Include in an Audit Policy

A typical Linux audit configuration focuses on events like:

Not all systems require the same level. For a personal laptop, heavy audit rules may be overkill; for a payment processing server, they may be mandatory.


Building an End‑to‑End Logging & Auditing Workflow

This is about how logs and audits flow through your environment.

1. Ingestion

2. Normalization

Different sources use different formats. Normalization common steps:

Central platforms and agents often provide parsers for common log formats.

3. Storage and Indexing

Design decisions:

Ensure:

4. Detection and Alerting

You can’t manually read all logs. Rely on:

Set alerts for actionable conditions; too many alerts cause people to ignore them.

5. Response and Enrichment

Responses range from manual to automatic:

Enrichment adds value:

Logging and Auditing for Different Environments

The “right” setup depends on scale and importance.

Single Server / Small Homelab

Goals:

Typical approach:

Small–Medium Organization

Goals:

Typical approach:

Enterprise / Compliance-Driven

Goals:

Typical approach:

Best Practices and Common Pitfalls

Best Practices

  1. Time synchronization is non-negotiable
    • Always run NTP/chrony.
    • Use UTC in logs and dashboards.
  2. Protect log integrity
    • Restrict access to logs (/var/log, audit logs, central platform).
    • Consider:
      • checksums/hashes for critical logs
      • append-only flags
      • shipping logs off-host as soon as possible
  3. Avoid logging sensitive data unnecessarily
    • Do not log:
      • plain-text passwords
      • full credit card numbers
      • secret keys and tokens
    • If necessary, mask or tokenize sensitive fields.
  4. Test your logging and alerting regularly
    • Simulate:
      • failed login bursts
      • service failures
      • audit events (e.g. reading a critical file)
    • Confirm:
      • events are generated
      • they reach the central system
      • alerts fire as expected
  5. Document your log schema and rules
    • Where are logs stored?
    • How long are they kept?
    • Which events are monitored?
    • What alerts exist, and who owns them?

Common Pitfalls

Using Logs and Audit Trails During an Incident

When something goes wrong—security breach, data loss, or major outage—logs and audits are your primary evidence.

A typical workflow:

  1. Define the timeframe
    • When was the issue first noticed?
    • Use alerts, user reports, or monitoring data as boundaries.
  2. Identify relevant sources
    • Authentication logs
    • Service logs
    • System logs (kernel, hardware)
    • Audit logs (for file and process activity)
  3. Build a timeline
    • List events by time:
      • user logins
      • commands run
      • configuration changes
      • crashes, restarts
    • Look for cause-and-effect relationships.
  4. Correlate across systems
    • Use hostnames, IPs, user IDs, and session IDs.
    • Tie together:
      • web requests
      • app logs
      • DB queries
      • OS-level audit events
  5. Preserve evidence
    • Copy relevant logs to a safe place.
    • Ensure they cannot be modified.
    • Document the steps you take.
  6. Feed back into improvements
    • After the incident, update:
      • logging rules (to capture what was missing)
      • alert rules (to detect earlier next time)
      • documentation and training

Integrating Logging and Auditing with Other Tools

Logging and auditing become much more powerful when combined with other systems:

Summary

In advanced Linux administration, logging and auditing are not optional—they are how you observe, understand, and defend your systems.

Key ideas:

Subsequent sections will dive into the specifics of systemd logging, traditional /var/log files, auditd, log rotation, and creating custom logs.

Views: 75

Comments

Please login to add a comment.

Don't have an account? Register now!