Check a server for malware
Look for unknown processes eating CPU, unexpected listening ports, logins you do not recognise, new users, and cron jobs or systemd timers you did not create. Confirm with package integrity checks and scanners such as rkhunter and ClamAV. If the server is compromised, copy your data, rebuild from a clean image, and rotate every key and password it held.
Recovery and troubleshooting guide, updated 2026-12-03
What are the typical signs of a compromise?
Most break-ins on internet-facing servers are automated and aim to use your resources, not to steal a specific file. The signs follow from that:
- CPU at 100 percent from a process with a random or innocent name such as
kworkerdsor[kthreadd]running from/tmp: a cryptocurrency miner. - Outgoing traffic you cannot explain, or a sudden jump in used outgoing traffic on your invoice: scanning, spam or denial of service attacks sent from your server.
- A mail queue full of messages you did not send.
- New user accounts, new lines in
authorized_keys, or a changed root password. - Cron jobs or systemd timers that fetch scripts with curl or wget.
- Logs that were cleared, or
lastshowing nothing at all.
A message from support about abuse coming from your IP is also a strong hint; take it seriously and start the checks below.
Which processes and ports should you look at?
Start with what is running and what is listening:
top -o %CPU
ps auxf --sort=-%cpu | head -30
ss -tulpn
ss -tnp state establishedFor any suspicious process ID, find out where it really comes from:
ls -l /proc/12345/exe
cat /proc/12345/cmdline | tr "\0" " "; echo
ls -l /proc/12345/cwdAn exe link pointing into /tmp, /dev/shm or /var/tmp, or ending in (deleted), is a red flag: legitimate services run from /usr. In the ss output, compare each listening port with what you installed. Port 22, 80 and 443 are expected on a web server; a listener on a high port owned by a process you cannot name is not.
How do you review logins and accounts?
Check who logged in, who tried, and which accounts exist:
last -n 30
lastb -n 30
journalctl -u ssh --since "7 days ago" | grep -E "Accepted|Failed" | tail -50
awk -F: "\$3 == 0 || \$3 >= 1000 {print \$1, \$3, \$7}" /etc/passwd
grep -E "^(sudo|wheel):" /etc/groupOn Rocky and Alma the SSH unit is sshd. Thousands of entries in lastb are normal background noise on any public IP. What matters is Accepted lines from addresses you do not know, any account other than root with user ID 0, and members of the sudo or wheel group you did not add. Then review keys for every user:
cat /root/.ssh/authorized_keys
cat /home/*/.ssh/authorized_keysWhere do attackers hide persistence?
An intruder wants to survive a reboot. Check every place that starts code automatically:
for u in $(cut -d: -f1 /etc/passwd); do crontab -l -u "$u" 2>/dev/null | sed "s/^/$u: /"; done
ls -la /etc/cron.d /etc/cron.hourly /etc/cron.daily
cat /etc/crontab
systemctl list-timers --all
systemctl list-unit-files --state=enabled
ls -la /etc/systemd/system
cat /etc/ld.so.preload 2>/dev/null
ls -la /etc/profile.dPay special attention to /etc/ld.so.preload: on a normal system it does not exist or is empty. A library listed there is loaded into every program and is a classic way to hide processes from ps and files from ls. Also look at shell start files such as /root/.bashrc and /root/.profile for odd lines at the end.
How do you check package integrity?
Package managers store checksums for every file they installed. Comparing them reveals replaced binaries:
# Ubuntu and Debian
apt install debsums
debsums -s
# Rocky, AlmaLinux, CentOS Stream, Fedora, openSUSE
rpm -Va | grep -v "^.......T"debsums -s prints only files whose content changed. In rpm -Va output, a 5 in the third column means the checksum differs; changed config files (marked c) are often your own edits and expected. A changed /usr/bin/ps, /usr/bin/ss or /usr/sbin/sshd is serious.
Keep in mind that a rootkit with full control can lie to these tools too. Their value is in catching the common, careless cases.
Which scanners are worth running?
Three tools from the standard repositories cover the usual ground:
- rkhunter: compares system binaries with known good properties and looks for known rootkit files.
apt install rkhunter, thenrkhunter --propupdon a clean system andrkhunter --check --sklater. - chkrootkit: a separate set of rootkit signatures.
apt install chkrootkitand runchkrootkit -q. - ClamAV: a general malware scanner, useful for web roots where uploaded PHP shells hide.
apt install clamav,freshclam, thenclamscan -ri /var/www. On the dnf family the packages are in EPEL.
All of them produce some false positives; read each warning and compare with what you know about the system. A clean scan is reassuring, not proof.
What should you do if the server is compromised?
Cleaning a compromised system file by file is unreliable, because you never know what you missed. The reliable path is:
- Stop the damage: if the server attacks others, stop the offending service, or shut the server down and tell support.
- Save your data, not your system: copy databases (as dumps), uploads and configs you need, as described in copying data off a broken server. Do not copy binaries or scripts you cannot read.
- Rebuild from a fresh image in the console. The IP stays the same.
- Rotate every secret the server held: SSH keys that lived on it, database passwords, API tokens, and the keys of any other system it could reach.
- Fix the cause before going live again: update software, remove the weak password or vulnerable plugin, and harden SSH as in the hardening guide.
A backup restore is an option only if you know the backup day is from before the intrusion; otherwise you restore the attacker as well.
Should you report the incident?
Yes, to support, if your server sent spam, scans or attacks, so they know the issue is being handled; see the acceptable use policy for what counts as abuse. If personal data of your users may have been exposed, data protection rules in many countries require you to notify the affected people or an authority within a short time. Write down what you found, with times and commands, while it is fresh; that record helps both with the report and with avoiding a repeat.
Questions about this guide
Is a high load always a miner?
No. Check the process first; a busy database or a backup job also uses CPU. Miners usually run from /tmp or /dev/shm with odd names.
Can I just delete the miner and move on?
The miner is rarely alone. There is usually a cron job, a timer or a key that brings it back. A rebuild is the safe choice.
How do attackers usually get in?
Weak or reused passwords on SSH, outdated web applications or plugins, and exposed admin panels or databases without a password.
Does the network DDoS filtering stop break-ins?
No. It filters floods of traffic aimed at your IP. Logins and application attacks need your own hardening and updates.
How often should I run rkhunter?
A daily run from cron with mail or log alerts is common. Run rkhunter --propupd after each normal system update.
Should I keep the backup add-on after an incident?
Yes, and note which days were taken before the intrusion, so you never restore a compromised copy by mistake.