Course contentsShow
← Security
Lesson 1478 of 3,05230. Operating System Security - MonitoringFree lesson

journalctl Query and Filtering

Master journalctl commands to query logs by unit, time range, priority, and custom fields efficiently.

journalctl Query and Filtering

What you'll learn: How to efficiently search and filter systemd journal logs to investigate security events and system behavior.

The Power of Targeted Log Queries

Now that you understand systemd journal architecture, it's time to master journalctl—the command-line tool for querying those binary logs. Think of journalctl as a search engine for your system's memory: without the right query syntax, you're drowning in data; with precise filters, you find exactly what you need in seconds.

Core Query Techniques

By service/unit:

journalctl -u sshd.service        # View SSH daemon logs only
journalctl -u nginx -u postgresql  # Multiple units

By time range:

journalctl --since "2024-01-15 14:30:00"
journalctl --since yesterday --until "1 hour ago"
journalctl --since 09:00 --until "1 hour ago"

By priority level:

journalctl -p err                  # Errors and higher (crit, alert, emerg)
journalctl -p warning..err         # Range from warning to error

By custom fields:

journalctl _UID=1000              # Logs from specific user ID
journalctl _PID=1234              # Specific process
journalctl SYSLOG_FACILITY=10     # Security/auth facility

Combining Filters for Security Investigations

# Failed SSH attempts in the last hour
journalctl -u sshd --since "1 hour ago" | grep Failed

# Critical errors from any service today
journalctl -p crit --since today

# All security events with context
journalctl SYSLOG_FACILITY=4 SYSLOG_FACILITY=10 -o verbose

Use -f to follow logs in real-time (like tail -f) and -n 50 to limit output lines—essential when investigating active incidents without overwhelming your terminal.

Key Takeaway: Master journalctl's filtering by unit, time, priority, and fields to quickly isolate security-relevant events from millions of log entries, turning raw journal data into actionable intelligence.