How Do I Do Digital Forensics on Linux?
Linux digital forensics starts with evidence preservation, not ad hoc investigation. If you are handling an incident on a Linux host, isolate the system carefully, document every action, collect volatile data when needed, acquire forensic copies, hash your evidence, and analyze duplicates instead of the original machine. On Linux, the most useful artifacts often include logs, shell history, SSH activity, cron jobs, services, temporary files, and filesystem timelines.
Short Answer
Start by preserving evidence: isolate the host, document everything, collect volatile data if needed, acquire forensic images, hash all evidence, and analyze copies instead of the original system. On Linux, focus on logs, shell history, cron jobs, SSH activity, processes, persistence, and timeline reconstruction. Use a defensible process, not improvised commands.
Start With Preservation, Not Exploration
Digital forensics on Linux follows the same broad principles as forensics on any platform: preserve, collect, validate, analyze, and report. What changes is the evidence landscape.
Linux systems often expose valuable artifacts in plain-text logs, service definitions, scheduled tasks, package state, and command-line history. But those artifacts can also be changed quickly if responders act carelessly. Logging in repeatedly, restarting services, or running too many commands can overwrite the very evidence you are trying to preserve.
If the incident is still active, you should also coordinate forensic handling with containment. For guidance on broader incident handling, see /content/what-should-i-do-after-a-ransomware-attack.
1. Stabilize the Situation First
If the Linux host is part of an active incident, your first decision is whether to prioritize containment or evidence preservation. In a live compromise, disconnecting a server too early may destroy useful network context. Leaving it online too long may allow continued attacker activity.
At minimum:
- record date and time
- document hostname and IP addresses
- note who is handling the case
- capture why the system is being examined
- avoid logging in repeatedly
- avoid running unnecessary commands
- isolate the host from the network without powering it off if possible
Do not start “looking around” casually. Every command can change access times, logs, shell history, and process state.
2. Decide Whether Volatile Data Matters
If you suspect malware, in-memory-only payloads, active remote access, or encryption keys in RAM, live collection may be necessary before shutdown. Volatile data can include:
- running processes
- active network connections
- loaded kernel modules
- logged-in users
- memory contents
- mounted file systems
- current routing table
- ARP cache
This step is sensitive because live response changes the system. That does not make it wrong, but it does mean the activity must be documented and minimized.
A good practice is to record:
- exact commands used
- timestamps for each collection step
- output file locations
- external media or storage used
- any failures or deviations from plan
3. Preserve Storage Evidence Properly
For non-volatile evidence, acquire a forensic image of the disk or relevant volumes whenever practical. The key principles are:
- collect from the original media as read-only where possible
- calculate cryptographic hashes before and after transfer
- store originals securely
- analyze a copy, never the original
On Linux servers, full imaging may be complicated by uptime requirements, virtualization, cloud storage, LVM, or containers. In those cases, you may need a scoped acquisition plan covering:
- disk images or snapshots
- key directories such as
/etc,/var/log,/home,/root,/tmp,/var/tmp - web roots and application directories
- authentication artifacts
- SSH configuration and keys
- scheduled task locations
If the host was internet-facing or part of a larger intrusion, preserving network and authentication evidence early is especially important. You may also want to review /content/what-logs-should-i-preserve-during-a-cyber-incident.
4. Collect the Linux Artifacts That Matter Most
Linux forensics is often about reconstructing attacker behavior from ordinary system artifacts.
High-value areas include:
- authentication logs: SSH access, sudo usage, failed logins, privilege escalation
- shell history:
.bash_history,.zsh_history, though these may be incomplete or tampered with - cron and timers:
cron,anacron,systemdtimers - startup and persistence:
systemdservices, init scripts,rc.local, user autostart locations - logs:
/var/log/, including syslog, auth logs, kernel logs, web logs, and application logs - temporary directories:
/tmp,/dev/shm,/var/tmp - user and privilege artifacts:
/etc/passwd,/etc/shadow,/etc/sudoers, group membership - network traces: firewall rules, listening services, resolver settings, connection logs
- package and binary changes: package manager history, modified binaries, unusual file timestamps
Also check for signs of persistence such as:
- new service units
- modified SSH authorized keys
- suspicious cron entries
- reverse shells
- renamed binaries in standard paths
- unusual startup scripts
- unauthorized accounts or group changes
5. Build a Timeline of Activity
A timeline is often the fastest way to understand what happened. Correlate:
- file modification, access, and creation metadata where available
- authentication events
- command execution traces
- package installation times
- service creation or modification
- outbound connections
- log-clearing or tampering attempts
The goal is to answer:
- when initial access likely happened
- what the attacker did next
- whether privilege escalation occurred
- how persistence was established
- what data may have been accessed or exfiltrated
On Linux, timestamp interpretation matters. Normalize time zones and account for clock drift before drawing conclusions.
6. Watch for Common Persistence and Evasion Techniques
Attackers on Linux often try to blend into standard administration patterns. Watch closely for:
- unexpected SSH keys in user accounts
- changes to sudo permissions
- new or altered systemd services
- malicious cron jobs
- suspicious binaries placed in writable paths
- shell aliases or profile changes
- hidden files in home or temp directories
- unauthorized package installation
Sophisticated attackers may also:
- clear or rotate logs
- disable auditing
- unset shell history
- use in-memory tooling
- replace system binaries
- timestomp files
- create short-lived users or SSH keys
Absence of evidence is not evidence of absence. If logs are missing, that gap is itself a finding.
7. Maintain Chain of Custody and Evidence Integrity
Every acquired image, log bundle, and exported artifact should be hashed and tracked. Document:
- who collected it
- when it was collected
- how it was transferred
- where it was stored
- which hash values were used for integrity checking
Even for internal investigations, this discipline matters. It prevents confusion, supports defensible reporting, and helps maintain trust in the findings.
If you are storing evidence on an external system, secure that storage properly. Strong credential handling matters here too. A password manager such as 1Password can be useful for protecting case-related credentials, shared vault access, and investigation accounts, especially in small teams.
8. Analyze Safely and in Isolation
Do as much detailed analysis as possible on forensic copies, not the original host. That includes:
- parsing logs
- mounting disk images
- reviewing suspect binaries
- examining scripts
- correlating timestamps
- extracting indicators of compromise
If you need internet access while analyzing indicators, malware references, or attacker infrastructure, use a secure and controlled environment. For analysts working remotely or on untrusted networks, a reputable VPN such as NordVPN or Surfshark can help protect traffic in transit, though it is not a substitute for proper lab isolation.
If malware is suspected on analyst workstations or staging systems, additional endpoint scanning may also be useful. Tools like Malwarebytes can serve as one layer of protection on analysis endpoints, though they do not replace forensic rigor.
9. Report Findings Clearly
Your final output should not just list artifacts. It should explain:
- scope of systems examined
- evidence sources collected
- timeline of attacker or user activity
- confidence level of conclusions
- indicators of compromise
- limitations or missing data
- recommended containment and remediation steps
A useful forensic report should help technical responders, leadership, legal teams, and auditors understand both what happened and what should happen next.
Common Mistakes to Avoid
Logging in and investigating casually
That may contaminate evidence immediately. Live access should be deliberate, minimal, and documented.
Relying only on /var/log
Logs are important, but they are only part of the picture. Persistence, shell artifacts, services, SSH keys, temp files, and package changes often matter just as much.
Assuming deleted history means no evidence remains
Authentication logs, service configs, file metadata, application logs, and network artifacts can still reveal a lot.
Skipping hashes because it is an internal case
Hashing helps prove integrity in any investigation, including internal IR, compliance, and HR-related cases.
Rebooting too soon
A reboot can destroy volatile evidence, alter logs, and remove in-memory malware. It should be a conscious decision, not a reflex.
Final Takeaway
The practical answer is this: do Linux digital forensics with a repeatable, evidence-first workflow. Preserve the system, collect carefully, hash everything, analyze copies, and build a timeline from multiple artifacts instead of relying on any single log or history file. Good Linux forensics is less about memorizing commands and more about maintaining a defensible process from first contact to final report.
Disclaimer: This article may contain affiliate links. We earn a commission on qualifying purchases at no extra cost to you.