Best Tech & Security Platform
Followed by 1000+

GEANTECHNOLOGY

Your Trusted Source for IT Tutorials and Tech Insights

How to Analyze Linux Logs: A Blue Team’s Practical Guide

Aug 4, 2026 ahmed mokdad 7 min read

Every meaningful event on a Linux system leaves a trace somewhere — a failed SSH login, an unexpected sudo command, a firewall drop, a spike in 404s from a web server. The problem isn’t a lack of data; it’s knowing where to look and what pattern separates routine noise from an actual incident. This guide walks through the log sources that matter most, the commands blue teamers and sysadmins actually use day to day, and how to spot the anomalies that logs are trying to tell you about.

Quick answer: “Effective Linux log analysis means knowing where different event types live (/var/log/auth.log for authentication, the systemd journal for service-level events, web server and firewall logs for network activity), using grep, awk, and journalctl to filter that data down to what matters, and recognizing recurring attack patterns — brute-force attempts, unusual sudo usage, off-hours logins, and user enumeration scans — before they turn into a confirmed incident.”

Table of Contents

  1. Know Your Log Sources
  2. Two Logging Systems: Flat Files vs. the systemd Journal
  3. Key Linux Log Files and What They Contain
  4. Essential Commands for Authentication Analysis
  5. Log Rotation: Keeping Logs Useful and Available
  6. Anomaly Patterns Worth Watching For
  7. Threat Hunting Techniques on Linux Logs
  8. Parsing, Enrichment, and Scaling Beyond grep
  9. Conclusion

Know Your Log Sources

Before touching a single command, it helps to map out where different categories of evidence actually live. Logs generally fall into a handful of buckets, each useful for a different kind of investigation:

SourceExampleBlue Team Use Case
Operating System (Linux)/var/log/auth.logSSH login attempts, sudo usage
Operating System (Windows)Security.evtxLogons, process creation, privilege use
Network DevicesFirewall logs, DHCP logsBlocked traffic, address leasing
Web ServersApache/Nginx access & error logsSuspicious URIs, directory traversal, fuzzing
Security ToolsEDR, antivirus, SIEMThreat detections, lateral movement
Cloud InfrastructureAWS CloudTrail, Azure Activity LogAPI misuse, cloud privilege escalation

Knowing which bucket an incident likely falls into before you start searching saves significant time — there’s no point grepping web server logs for a suspected SSH brute-force attempt.

Two Logging Systems: Flat Files vs. the systemd Journal

Modern Linux distributions run two logging mechanisms side by side, and knowing which one you’re dealing with changes your approach entirely.

Plain-text files under /var/log/ are written by traditional syslog daemons (rsyslog, syslog-ng) and application processes directly. These are the classic auth.log, syslog, and application-specific logs you can grep and tail directly.

The systemd journal, queried through journalctl, stores structured, binary log data — including kernel messages, every service’s stdout/stderr, and audit events — and supports filtering by time, service unit, severity, or even the exact executable path that generated an entry. On most current systems, both exist simultaneously: use journalctl for systemd-managed services, and flat files for anything an application manages on its own.

Key Linux Log Files

Log FileDescription
/var/log/auth.logAuthentication events, sudo usage, SSH login attempts (Debian/Ubuntu)
/var/log/secureEquivalent to auth.log on RHEL-based distributions
/var/log/syslogGeneral system events and kernel messages
/var/log/messagesDaemon and system messages (RHEL/CentOS)
/var/log/wtmpBinary log of user logins and reboots
/var/log/btmpBinary log of failed login attempts
/var/log/lastlogLast login timestamp for every user
/var/log/sudo.logOptional dedicated sudo log, if configured

Rows of server racks representing centralized log collection Alt text: Data center servers generating and storing system logs

Essential Commands

These commands form the backbone of everyday authentication analysis and general triage:

View the last 20 SSH login failures:

grep "Failed password" /var/log/auth.log | tail -n 20

Follow system events in real time:

tail -f /var/log/syslog

Query successful SSH logins:

grep "Accepted password" /var/log/auth.log

Summarize failed logins by source IP:

grep "Failed password" /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr

Review sudo usage:

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

Show recent and failed logins from binary logs:

last     # recent logins (from wtmp)
lastb    # failed logins (from btmp)

Query a specific time window with journalctl:

journalctl --since "2026-06-30 14:00:00" --until "2026-06-30 14:10:00"

Pretty-print JSON-formatted logs (e.g., Suricata alerts):

cat eve.json | jq '.'

Log Rotation

Logs are only useful if they’re actually available when you need them — and if they haven’t already filled the disk. Most Linux distributions handle this with logrotate, configured through /etc/logrotate.conf and the individual files under /etc/logrotate.d/. It manages compression, rotation frequency, and eventual deletion so a busy service doesn’t quietly consume all available disk space.

Test a rotation configuration without applying it:

sudo logrotate --debug /etc/logrotate.conf

Quick PowerShell equivalent check on the Windows side, for mixed environments:

Get-EventLog -LogName Security | Measure-Object

Typical Retention Guidelines

Log TypeRecommended Retention
Authentication logs (SSH, RDP)180–365 days
Security logs (EDR, SIEM)1–3 years
Web server access logs90–180 days
Firewall, IDS/IPS logs90–365 days
Cloud API activity logs180–365 days
Compliance-regulated systems1–7 years

These are starting points, not hard rules — actual retention should be driven by your organization’s compliance obligations and incident-response needs, whichever is longer.

Anomaly Patterns

Raw log volume is meaningless without knowing which patterns actually indicate a problem. A few recurring ones are worth memorizing:

PatternIndicator
Multiple failed logins in a short windowBrute-force attempt
Login at an unusual timeInsider threat or compromised account
sudo use by an unauthorized-looking userPrivilege escalation
SSH access from an unexpected country/IPPossible lateral movement
Frequent switching between user accountsSession hijack or account enumeration

None of these are proof on their own — a developer working late isn’t automatically an insider threat — but each one is a reason to look closer.

Threat Hunting Techniques

Beyond passive monitoring, these targeted queries help surface activity that blends into normal log noise.

Hunting interactive root shell access. Direct root shells are unusual outside specific administrative tasks — worth flagging when they appear unexpectedly:

grep 'COMMAND=/bin/bash' /var/log/auth.log | grep 'USER=root'

Looking for lateral movement via SSH. Filter out known jump hosts or bastions to surface internal connections that shouldn’t be happening directly:

grep "Accepted password" /var/log/auth.log | grep -vE '192\.168\.0\.1|10\.0\.0\.1'

Monitoring a sudden sudo usage spike. Build a frequency table by user to catch accounts that suddenly start escalating privileges when they normally don’t:

grep "sudo" /var/log/auth.log | awk '{print $1, $2, $3, $9}' | sort | uniq -c | sort -nr

Detecting user enumeration scans. Repeated attempts against nonexistent usernames are a strong signal of automated account discovery:

grep "Invalid user" /var/log/auth.log | awk '{print $(NF)}' | sort | uniq -c | sort -nr

Querying audit events directly, if auditd is enabled:

ausearch -m USER_LOGIN -ts recent
ausearch -ua 1001

Parsing and Enrichment

Manual grep-and-awk workflows work well for triage and small environments, but they don’t scale to fleets of servers or high log volumes. For that, dedicated parsing and enrichment tools take over:

  • Logstash, Fluent Bit, or syslog-ng convert raw log lines into structured, enriched events — adding context like geolocation, asset ownership, or threat-intel matches before the data ever reaches an analyst.
  • Centralized platforms like an ELK stack or a SIEM aggregate logs from every host into one searchable index, which is essential once you’re correlating events across more than a handful of machines.
  • journalctl‘s structured filtering — by unit, priority, time window, or even the exact executable path (_EXE=/usr/bin/python3) — is worth learning well, since it can isolate every log line generated by a suspicious process across a system’s entire history without needing an external pipeline.

The right tool depends on scale: a single server is well served by grep and journalctl; a fleet of dozens or hundreds needs centralized aggregation to make correlation practical at all.

Conclusion

Log analysis isn’t about reading everything — it’s about knowing which file holds the answer to a specific question, and which command gets you there fastest. Authentication logs tell you who’s trying to get in and how; the systemd journal tells you what services actually did; retention policy determines whether that evidence still exists when you need it weeks later. Building fluency with grep, awk, journalctl, and a short list of known anomaly patterns covers the vast majority of real-world investigations, and gives you a solid foundation before reaching for a full SIEM.

Want more hands-on Linux guides like this?

Subscribe to the GEANTECHNOLOGY newsletter for weekly tutorials on networking, cybersecurity, and server administration — or take the next step and secure your infrastructure further.

Leave a Reply

Your email address will not be published. Required fields are marked *