Linux Log Analysis for Incident Response
Linux systems record activity across several sources, and no single log tells the whole story. During an incident, investigators may need to correlate authentication events, service activity, proce…
Linux systems record activity across several sources, and no single log tells the whole story. During an incident, investigators may need to correlate authentication events, service activity, process execution, network changes, and application behavior—often across systems with different logging configurations.
Effective linux log analysis incident response starts before searching for suspicious entries. Preserve evidence, establish the system’s time context, identify which sources are available, and document the commands you run. Then build a timeline by correlating records rather than treating one message as proof of an attack.
This guide compares the main Linux logging approaches, explains how to collect and analyze records, and provides criteria for choosing a defensive logging design.
What Linux logs can—and cannot—tell you
Linux logging is not one unified record of every action. Different components emit different events, and logging depends on configuration, software, permissions, and retention.
Common sources include:
- systemd journal: Records from system services, the kernel, and other processes managed by systemd. Depending on configuration, journal data may be stored persistently or only in volatile storage.
- Traditional syslog files: Files such as `/var/log/syslog` or `/var/log/messages` contain events routed by a syslog implementation. Exact filenames vary by distribution and configuration.
- Authentication records: Files such as `/var/log/auth.log` or `/var/log/secure` may record SSH, `sudo`, and other authentication-related events.
- Audit records: Linux Audit can record configured security-relevant events, such as certain system calls, changes to selected files, and execution events. Coverage depends on the rules in place.
- Application and service logs: Databases, web servers, containers, and custom applications may write to files, the journal, or a separate logging system.
- Supporting evidence: Shell history, package records, firewall logs, process accounting, and network telemetry can help answer specific questions, but each has important limitations.
A missing event does not prove an action did not happen. Logging may not have been enabled, records may have rotated or been deleted, a service may have written elsewhere, or an attacker may have tampered with local evidence. Logs are evidence to evaluate in context, not a complete account of system activity.
First steps: preserve evidence before investigating
If a system may be compromised, coordinate with your incident response process before making changes. Actions such as restarting services, rebooting, installing tools, changing configuration, or cleaning up suspected malware can alter evidence.
1. Record the system and time context
Capture the hostname, current time, timezone, and clock synchronization status. For example:
```bash
hostnamectl
date --iso-8601=seconds
timedatectl status
```
The leading space before `date` is optional; run the command as `date --iso-8601=seconds`. Compare timestamps in a consistent timezone when correlating systems. A clock that is skewed or recently adjusted can make an otherwise accurate timeline misleading.
2. Identify the logging setup
Check which services and files are present without changing configuration:
```bash
systemctl is-active systemd-journald
systemctl is-active rsyslog
ls -ld /var/log/journal /run/log/journal 2>/dev/null
find /var/log -maxdepth 2 -type f -printf '%p\n' 2>/dev/null | sort
```
A command returning a nonzero status may simply mean that a service or path is absent. Avoid assuming that every distribution uses the same filenames or logging stack.
3. Preserve and document collected data
When policy and access permit, export relevant records to a separate evidence location or a controlled collection system. Record the source host, collection time, commands, operator, and any errors. Protect collected files from unauthorized access and calculate hashes where appropriate:
```bash
sha256sum collected-journal.txt
```
A hash can help detect later changes to the collected copy; it does not establish that the original logs were complete or untampered with before collection. For serious incidents, use approved forensic procedures and consider acquiring broader system evidence, including volatile data, before it is lost.
Approach 1: Analyze the systemd journal
The `journalctl` command can filter journal records by time, boot, unit, priority, and other fields. It is often the fastest starting point on a systemd-based host.
Useful journal queries
Show records from the current boot:
```bash
journalctl -b --no-pager
```
Inspect a service over a specific time range:
```bash
journalctl -u ssh.service \
--since '2025-03-01 08:00:00' \
--until '2025-03-01 10:00:00' \
--no-pager
```
The service may have a different unit name, such as `sshd.service`; check the host’s units rather than assuming a name. Use an incident-relevant time range, and confirm the timezone used by the host and by your query.
Review kernel messages from the current boot:
```bash
journalctl -k -b --no-pager
```
Export journal records in JSON for structured processing:
```bash
journalctl -b -o json --no-pager > journal-current-boot.json
```
Treat exports as sensitive data. They can contain usernames, hostnames, paths, command arguments, and other information that should not be shared casually.
Strengths and tradeoffs
Advantages: Journal records offer useful metadata and flexible filtering. On systems with persistent journal storage, records may be available across reboots, and fields can help distinguish a service’s messages from other events.
Limitations: Journal retention and persistence vary. Volatile journal data may disappear after a reboot, and a local administrator or attacker with sufficient access may be able to affect local records. Journal formats and available fields can also differ between systems and versions.
Use the journal as a structured source, but verify persistence settings and correlate important findings with other evidence.
Approach 2: Analyze traditional log files
On systems using a syslog daemon, text files in `/var/log` remain an important source. Their names and routing rules depend on the distribution and local configuration.
Search a file for authentication-related terms:
```bash
sudo grep -iE 'failed password|accepted password|sudo:' /var/log/auth.log
```
On systems that use a different authentication log path, substitute the appropriate file. Search rotated logs too, including compressed archives when available:
```bash
sudo zgrep -iE 'failed password|accepted password|sudo:' /var/log/auth.log*
```
Inspect a time window in a text log with `awk` when timestamps use a consistent, sortable format. For example, this searches a syslog-style file for a particular date and hour prefix:
```bash
sudo grep '^Mar 1 09:' /var/log/syslog
```
This simple prefix match is not a universal timestamp parser. It may miss records with different spacing, year conventions, timezone handling, or formats. For larger investigations, normalize timestamps with a parser that understands the source format.
Strengths and tradeoffs
Advantages: Text files are easy to inspect with standard tools, copy, and process with scripts. They may preserve records independently of the journal when both are configured.
Limitations: Files can be rotated, compressed, truncated, or deleted. Traditional syslog formats may omit structured metadata, and records from separate files may use different timestamp conventions. A plain text search also finds strings, not necessarily meaningful event sequences.
Check rotated files and syslog configuration before concluding that an event is absent. Do not alter rotation or retention settings on a suspected host before preserving relevant evidence.
Approach 3: Use Linux Audit records
The Linux Audit subsystem can provide more targeted security telemetry when audit rules have been configured in advance. The `ausearch` utility can query audit records by time, event type, or other criteria.
For example, search audit records for events associated with a file path:
```bash
sudo ausearch -f /etc/sudoers
```
Review audit status and rules where permitted:
```bash
sudo auditctl -s
sudo auditctl -l
```
These commands inspect the current audit subsystem; they do not guarantee that relevant events were captured historically. Audit rules must have been active when the event occurred, and the selected rules determine what is recorded. Audit logs can also grow quickly, so rule design, storage, access control, and forwarding need to be planned.
Strengths and tradeoffs
Advantages: Audit records can provide detailed, security-focused event data and can help answer questions that general-purpose service logs do not cover.
Limitations: Audit coverage is rule-dependent. Broad rules can create substantial volume and operational overhead, while narrow rules can miss activity investigators later need. Audit records are not a substitute for application, authentication, or network logs.
Choose audit rules based on specific investigative questions and operational requirements. Test them, monitor whether the audit pipeline is functioning, and protect records from unauthorized modification.
Build an incident timeline
A timeline helps connect separate records into a sequence. Start with the incident’s known time window, then widen it to account for clock drift, delayed reporting, and uncertainty about when activity began.
A practical workflow is:
1. Define the question. For example: Was an account accessed remotely, and what happened after login?
2. Collect the relevant sources. Include authentication logs, journal records for affected services, audit records if available, and application or network telemetry.
3. Normalize time. Record each source’s timezone and timestamp format. Note clock changes and known synchronization issues.
4. Search for related events. Look for successful and failed logins, privilege escalation, service changes, new scheduled tasks, file changes, and unexpected outbound connections.
5. Correlate identifiers. Compare usernames, source addresses, process IDs, session IDs, service names, and file paths where those fields exist. A shared username or IP address alone does not prove two events are connected.
6. Document uncertainty. Separate observed facts from hypotheses, and note gaps such as missing logs or unknown retention periods.
For an initial SSH review, use the authentication log when present and check the journal as a second source:
```bash
sudo grep -iE 'sshd.*(failed|accepted)' /var/log/auth.log
sudo journalctl -u ssh.service --since '2025-03-01 00:00:00' --no-pager
```
Adjust the path, unit name, and time window for the host. Then compare candidate events with identity-provider records, VPN or firewall telemetry, and endpoint or application evidence if those sources are available.
Choosing a logging design for response readiness
There is no universally best logging approach. Choose a design based on the questions responders must answer, the systems in scope, storage constraints, and the consequences of losing local evidence.
| Approach | Best suited for | Main tradeoff |
|---|---|---|
| Systemd journal | Filtering service and kernel events on systemd hosts | Persistence and retention depend on configuration |
| Traditional syslog files | Familiar text-based collection and compatibility | File rotation and less structured records can complicate correlation |
| Linux Audit | Capturing selected security-relevant activity | Requires careful rule design and volume management |
| Centralized collection | Cross-host correlation and protecting copies from local loss | Requires reliable transport, access controls, retention planning, and monitoring |
A defensive design commonly combines sources rather than choosing only one. Consider these criteria:
- Investigation needs: Identify the questions responders need to answer, such as who accessed a host, which privileged actions occurred, or when a service configuration changed.
- Coverage: Confirm that required events are generated and collected. Logging a service’s errors does not necessarily record who changed its configuration.
- Retention: Set retention to match operational and investigative needs. Verify that logs survive reboots and remain available for the required period.
- Centralization: Forward important records to a separately controlled collector when appropriate. Central copies can remain available if a host is lost or its local logs are altered, but they need protection and reliable delivery.
- Time consistency: Synchronize system clocks and retain enough timestamp context to identify timezone and clock changes.
- Access control and integrity: Restrict who can read, change, or delete logs. Monitor logging services and forwarding health, and protect stored records against unauthorized access.
- Volume and privacy: Balance useful detail against storage, performance, and privacy requirements. Avoid collecting sensitive data without a clear purpose and appropriate safeguards.
- Testing: Run tabletop exercises or controlled tests to confirm that expected events appear in the right places and can be retrieved by responders.
Local logs are useful for fast triage, but they should not be the only evidence source for systems where tampering or host loss is a concern. Centralized collection can improve resilience and cross-host analysis, but it does not automatically guarantee completeness: collection gaps, filtering, transport failures, and misconfigured retention still need attention.
Common pitfalls and troubleshooting
The expected log file is missing
The host may use a different distribution convention, send records only to the journal, or route events to another destination. Inspect available files and check the relevant service’s configuration. Do not treat an absent filename as proof that no events were recorded.
`journalctl` shows no older records
The journal may be volatile, the records may have expired under retention settings, or the query may target the wrong boot, unit, or time range. Check available boots with `journalctl --list-boots` and confirm the host’s clock and timezone. If the system has rebooted, volatile records from an earlier boot may no longer be available.
Authentication logs do not agree
A service may send messages to the journal, a syslog file, or both. Differences can also result from filtering, buffering, time settings, or retention. Preserve both sources and compare timestamps and event details before drawing a conclusion.
A grep search returns too many or too few results
Terms vary between software versions and configurations. Search a bounded time range, inspect the surrounding context, and use additional identifiers such as usernames or source addresses. A text match is a lead for investigation, not a verdict.
Audit records do not show the action you expected
Review which audit rules were active during the relevant period and whether the audit service was operating. Current rules do not establish what was captured in the past. If coverage was not enabled, document the gap and seek corroboration from other sources.
The host may be actively compromised
Avoid cleanup or configuration changes that could destroy evidence. Follow your organization’s containment and forensic procedures, restrict unnecessary access, and involve incident responders. Decisions such as isolating a host should account for operational impact and the risk of ongoing activity.
FAQ
Which Linux logs should I check first during an incident?
Start with the incident’s time window and affected service. Check authentication records for access questions, the journal or syslog files for service and system activity, and application logs for application behavior. Add audit, network, and identity-provider records when available. The best first source depends on the incident hypothesis and the host’s logging configuration.
Can `journalctl` replace traditional log files?
Not in every environment. Some systems rely mainly on the journal, while others forward records to traditional files or a central syslog service. The sources may contain different information or have different retention. Verify what is configured and preserve relevant sources rather than assuming they are interchangeable.
Do Linux logs prove that a user performed an action?
Usually, a log entry supports an assessment; it does not prove attribution on its own. Accounts can be shared or compromised, records can be incomplete, and timestamps can be inaccurate. Correlate account activity with session details, host state, identity records, and other evidence, and clearly distinguish conclusions from assumptions.
How can I make Linux logs more useful for future incidents?
Define the events responders need, configure suitable retention and audit rules, synchronize clocks, forward important records to a protected collector, restrict access, monitor collection health, and test retrieval. Review the design after incidents and system changes.
Conclusion
Linux log analysis for incident response works best as a disciplined process: preserve records, understand how the host logs activity, search the sources relevant to the question, and correlate findings into a time-aware timeline. The journal, traditional log files, and Linux Audit each provide different strengths and have different gaps.
For a resilient defensive design, combine sources where they answer distinct questions, plan retention and access controls, and consider centralized collection for important records. Most importantly, test the design before an incident. Responders should know which logs exist, how to retrieve them, and what conclusions those records can—and cannot—support.