The first 30 minutes after discovering a compromised Linux server usually decide how much evidence remains available.
One rushed reboot or cleanup attempt can wipe logs, terminate malicious processes, or remove network activity that investigators still need to review. Attackers also do not usually stay on one system for long once access is established.
Early response is mostly about preserving visibility. Collect process information. Save network connections. Limit access carefully before making major changes to the system.
Start by confirming the server is actually compromised. Broken applications, failed deployments, and unstable services can create symptoms that look malicious at first.
Early triage is mostly about identifying unauthorized access, suspicious processes, and unexpected network activity before making changes to the system.
who
w
last -a
Look closely at:

An SSH login from another country at 3 AM does not automatically confirm compromise, but it should immediately raise questions. The same goes for service accounts logging in interactively when they normally do not.
Once login activity looks suspicious, move directly into process inspection. Attackers often leave behind running malware, reverse shells, persistence scripts, or crypto miners.
ps auxf
top
pstree -p
This stage is less about memorizing process names and more about spotting behavior that feels wrong for the system.
Things worth investigating include:
Suspicious Behavior | Why It Matters |
Processes running from | Malware often hides in temporary directories |
Randomized process names | Attackers rename malware to avoid detection |
Unexpected parent-child relationships | A web server spawning shells is a bad sign |
High CPU usage with no explanation | Common with crypto mining malware |
Shells started by application users | May indicate command execution abuse |
A compromised web server spawning /bin/bash underneath an Apache or Nginx process deserves immediate attention.
After checking processes, inspect network activity. A server talking to unfamiliar systems or listening on unexpected ports may already be under remote control.
ss -plant
lsof -i -P -n
Pay attention to:
![]()
A reverse shell often appears as a process maintaining an outbound connection to a remote host over a strange high-numbered port. If the server normally only handles web traffic but suddenly maintains persistent outbound sessions to external infrastructure, that is not normal operational behavior.
In most cases, rebooting a compromised Linux server too early destroys valuable evidence. Memory-resident malware disappears. Active network connections vanish. Temporary files get deleted. Shell history stored only in memory may never be recoverable again.
A reboot can also terminate the exact malicious process you were trying to investigate. That sounds helpful until you realize it removes the ability to understand what the attacker was doing, how they got in, and whether they still have access somewhere else.
The following artifacts may disappear after a reboot:
/tmp Avoid rebooting the server unless the situation is actively getting worse. Preserve logs first. Save process information. Capture active network connections before changing services or killing processes.
In ransomware or destructive attacks, emergency shutdowns may still become necessary. Outside of those situations, immediate reboots usually create more problems for the investigation.
Most compromised servers should be isolated quickly, but investigators still need access to the system. The goal is to limit attacker movement without cutting off visibility completely.
Good containment limits external access while keeping the server reachable for evidence collection and review.
Action | Why It Helps |
Remove the server from the load balancer | Prevents users from reaching a compromised application |
Restrict inbound traffic with firewall rules | Limits new attacker access |
Isolate the system in a dedicated VLAN | Reduces lateral movement risk |
Block internet egress traffic | Stops outbound command-and-control communication |
Preserve secure SSH access | Allows investigators to continue evidence collection |
A cloud workload might be isolated by changing security groups. An on-premises server might move into a quarantine VLAN. The exact method changes between environments, but the objective stays the same.
Some responses create more problems than the attackers themselves.
![]()
Deleting malware immediately feels productive, but it often destroys indicators investigators need later. The same malicious file may reveal persistence methods, attacker tooling, or lateral movement paths across the environment.
Containment should slow the attacker down without destroying the evidence trail.
Volatile evidence disappears fast. Running processes terminate. Network connections close. Logs rotate. This is the stage where responders start preserving everything they may need later for investigation, reporting, or legal review.
Begin with process information.
These commands create snapshots of currently running processes.
ps auxf > /root/processes.txt
pstree -p > /root/pstree.txt
The redirected output preserves the process tree exactly as it existed during the investigation. That matters because attackers often terminate malware once they realize they have been detected.
Move next into network evidence.
ss -plant > /root/network_connections.txt
lsof -i -P -n > /root/open_sockets.txt
This helps identify:
![]()
A single established connection to an unfamiliar VPS provider can become the clue that ties the compromise together later.
Then, preserve user activity.
who > /root/logged_in_users.txt
last -a > /root/login_history.txt
Historical login records often reveal how long the compromise existed before detection. Attackers regularly use valid credentials after initial access, especially when moving laterally.
Logs should also be preserved before rotation occurs.
cp -r /var/log /root/log-backup
journalctl > /root/journalctl.txt
Linux systems rotate logs automatically. A busy server may overwrite critical authentication or application records quickly, especially during active attacks.
Useful logs commonly include:
Log Source | What It Reveals |
| SSH logins and failed authentication |
| Security-related events on RHEL-based systems |
| Systemd event history |
Web server logs | Exploitation attempts and suspicious requests |
Cron logs | Unauthorized scheduled tasks |
At this stage, documentation matters almost as much as evidence collection. Record timestamps. Save commands used during the investigation. Keep notes on every change made to the server.
Attackers rarely compromise a server and leave voluntarily. Persistence mechanisms help them regain access after reboots, password resets, or partial cleanup efforts. This is why compromised systems often appear clean at first and then become compromised again days later.
Cron jobs are one of the most common persistence methods on Linux systems.
crontab -l
ls -la /etc/cron*
Look for:
![]()
/tmp Attackers like cron because it survives reboots and blends into normal system administration.
SSH keys are another common persistence method, especially after credential theft.
cat ~/.ssh/authorized_keys
Unauthorized SSH keys allow attackers to reconnect without passwords. Compare keys against known administrators and remove anything unexplained only after preserving copies for investigation.
Persistence also appears inside systemd services.
systemctl list-units --type=service
systemctl list-unit-files
Suspicious services often:
A fake service named system-update.service launching a binary from /tmp/.cache should not be ignored.
Startup scripts deserve inspection too.
Common locations include:
/etc/profile
/etc/rc.local
/etc/init.d/
/etc/bash.bashrc
Attackers sometimes inject commands directly into startup scripts so malware launches every time a user logs in or the server boots.
Kernel-level persistence is harder to detect and far more dangerous. If root access was obtained, trust in the operating system itself becomes questionable.
Understanding the initial entry point matters because cleanup without fixing the original weakness usually leads to reinfection. Attackers rarely use complicated techniques when simple exposure works.
The most common Linux compromise paths include:![]()
Authentication logs provide a good starting point.
lastb
grep "Failed password" /var/log/auth.log
Large numbers of failed SSH logins may indicate brute-force activity. A successful login immediately after repeated failures deserves investigation.
Web servers should also be reviewed carefully. Exploited applications often leave traces in access logs.
Things to look for include:
Indicator | Possible Meaning |
Requests containing long encoded strings | Command injection attempts |
Requests to unknown PHP or JSP files | Web shell activity |
POST requests to admin endpoints | Credential abuse |
Repeated exploit attempts | Automated scanning |
Outdated packages create another common entry point. Attackers routinely target publicly known vulnerabilities within days of disclosure. The longer internet-facing systems remain unpatched, the higher the risk becomes.
The investigation may eventually show that the compromise began outside the server itself. Stol
A compromised Linux server can turn into a larger incident quickly if the response is rushed. Reboots, cleanup attempts, and configuration changes made too early often remove the evidence investigators still need.
Early response work is mostly about preserving visibility long enough to understand the scope of the compromise. Save process data. Preserve logs. Identify active connections. Check whether the attacker established persistence or moved into other systems.
A server may also appear stable after basic remediation while the original access path still exists. Unpatched applications, exposed admin services, stolen SSH keys, and reused credentials commonly lead to repeated compromise.
In higher-severity incidents, rebuilding from a trusted image is often safer than attempting partial cleanup on a compromised host. Especially after root-level access or suspected persistence inside the operating system.
Should I disconnect a compromised Linux server from the network immediately?
Usually, yes, but isolation should be controlled. The goal is to limit attacker movement while preserving evidence and maintaining investigator access.
Instead of powering the server off immediately, restrict inbound and outbound traffic carefully. Remove the system from production traffic if possible while preserving secure access for forensic review.
Should I reboot a hacked Linux server?
Usually no. Rebooting destroys volatile evidence, including memory artifacts, active attacker sessions, temporary malware files, and live network connections.
Exceptions exist during destructive ransomware events or situations where active compromise threatens other systems immediately.
What logs should I check after a Linux server compromise?
Start with authentication and system logs.
Common sources include:
/var/log/auth.log/var/log/securejournalctlThese logs help identify login activity, exploitation attempts, persistence, and lateral movement.
How do attackers maintain persistence on Linux servers?
Attackers commonly maintain persistence through:
Persistence mechanisms are designed to survive reboots and partial cleanup.
Can a compromised Linux server ever be trusted again?
Sometimes, but root-level compromise changes the situation significantly.
If attackers gained administrative access, complete trust in the operating system may be impossible to restore confidently. Many organizations rebuild compromised systems entirely instead of attempting a deep cleanup.
What is the first thing to collect during incident response?
Volatile evidence should be collected first.
That usually includes:
This information disappears quickly once systems reboot or attackers detect investigation activity.