A compromised server rarely announces itself. More often you notice something odd: CPU at 100% with no traffic, a warning from your provider about outgoing attacks, spam complaints, or your website redirecting mobile visitors to a casino. This guide lists the common signs, shows how to investigate each one, and explains what to do if you confirm a compromise.
One important principle first: once an attacker has had root access, you cannot fully trust anything on the system — including the tools you use to investigate. The goal of an investigation is to understand what happened and protect your data; the safe end state is almost always a clean rebuild.
Common warning signs
| Sign | Often means |
|---|---|
| CPU constantly high with low traffic | Cryptocurrency miner |
| Abuse report: SSH scanning or DDoS from your IP | Server used as a bot |
| Spam complaints, IP on blacklists | Mail sent by a malicious script |
| Unknown users, SSH keys or cron jobs | Persistence installed by an attacker |
| Website shows spam links or redirects | Web application compromise (often CMS plugins) |
| Bandwidth spike outbound | Attacks, scanning or data being copied out |
| Logs deleted or with gaps | Someone covering tracks |
Commands behave strangely (ps, ls missing files) |
Possible rootkit |
Step 1: Look at what is running
top -c # sort by CPU; press Shift+M for memory
ps auxf --sort=-%cpu | head -30 # process tree
Suspicious signs:
- Random names (
kdevtmpfsi,xmrig,.x, strings of letters) or names imitating kernel threads but running as a normal user. - Processes running from
/tmp,/var/tmp,/dev/shmor a hidden directory. - Processes owned by
www-data,nginxorapachethat are not PHP-FPM or the web server.
Find where a process’s binary lives, even if the file was deleted:
ls -l /proc/PID/exe
cat /proc/PID/cmdline | tr '\0' ' '; echo
ls -l /proc/PID/cwd
(deleted) next to the exe path means the program deleted itself after starting — a strong sign of malware.
Step 2: Check network connections
sudo ss -tupn # established connections with process names
sudo ss -tulpn # listening ports
Look for:
- Connections to unusual ports such as 3333, 4444, 5555, 14444 (common mining pool ports) or IRC (6667).
- Many outgoing connections to port 22 (your server is scanning others) or port 25 (sending spam).
- Listening ports you did not open.
Step 3: Check users, keys and sudo
awk -F: '$3 == 0 {print $1}' /etc/passwd # users with UID 0 (should be only root)
awk -F: '$7 !~ /(nologin|false)$/ {print $1, $7}' /etc/passwd # accounts that can log in
sudo cat /root/.ssh/authorized_keys
sudo find /home -name authorized_keys -exec ls -l {} \; -exec cat {} \;
sudo cat /etc/sudoers /etc/sudoers.d/* 2>/dev/null | grep -v '^#'
Unknown keys in authorized_keys are one of the most common backdoors.
Step 4: Check scheduled tasks and startup
Attackers make sure their code comes back after a reboot:
sudo crontab -l; for u in $(cut -f1 -d: /etc/passwd); do sudo crontab -u $u -l 2>/dev/null | sed "s/^/$u: /"; done
ls -la /etc/cron.* /var/spool/cron* 2>/dev/null
systemctl list-unit-files --state=enabled
ls -lt /etc/systemd/system/ | head
cat /etc/rc.local 2>/dev/null
grep -r "curl\|wget" /etc/profile /etc/profile.d/ /root/.bashrc /home/*/.bashrc 2>/dev/null
A cron line that downloads and runs a script with curl … | sh or wget -q -O - … | bash is a classic malware re-infection mechanism.
Step 5: Check logins
last -n 30 # successful logins
sudo lastb -n 30 # failed logins (if recorded)
sudo journalctl -u ssh --since "7 days ago" | grep Accepted # "sshd" on RHEL family
An Accepted password line for root from an IP you do not recognise tells you how the attacker got in.
Step 6: Check recently changed files
sudo find /etc /usr/bin /usr/sbin /usr/local/bin -mtime -7 -type f -ls 2>/dev/null
sudo find /tmp /var/tmp /dev/shm -type f -ls
sudo find /var/www -name "*.php" -mtime -7 -ls
Verify system binaries against the package database:
sudo debsums -s # Debian / Ubuntu (apt install debsums)
sudo rpm -Va | grep '^..5' # AlmaLinux / Rocky: files whose checksum changed
Changed files in /usr/bin or /usr/sbin that you did not update are a serious red flag. Scan web files and the system for known malware as described in scanning a Linux server for malware.
Step 7: Web application checks
For WordPress and other PHP sites, look for:
grep -rlE "eval\(base64_decode|gzinflate\(base64|str_rot13\(|assert\(\$_" /var/www --include=*.php
find /var/www -name "*.php" -path "*uploads*"
PHP files inside an uploads folder are almost always malicious. Also check for new admin users in the CMS and unknown plugins.
If you confirm a compromise
1. Contain
- Do not simply delete the miner and carry on. The way in is still open and other backdoors are likely.
- Restrict network access: allow SSH only from your IP in the firewall, and if the server is attacking others, stop the offending service or take the site offline.
- If your provider has suspended the server for outgoing abuse, reply to the ticket with what you found and your plan.
2. Preserve and copy what you need
- Copy your data (database dumps, uploads, configuration you wrote) to a safe place. Do not copy executables or the whole filesystem blindly.
- Save logs that help explain the attack.
3. Rebuild
- Reinstall the operating system from the control panel (or deploy a new server).
- Apply updates, create a sudo user, use SSH keys only, set up the firewall and Fail2ban.
- Reinstall applications from official sources; reinstall the CMS core, themes and plugins fresh, then restore only content and database.
- Scan restored web files before going live.
4. Rotate every secret
Assume all secrets on the server were stolen: SSH keys stored there, database passwords, API keys, .env files, SMTP credentials, CMS admin passwords, and any password reused elsewhere.
5. Find and close the entry point
Most compromises come from: weak or reused SSH passwords; outdated CMS plugins; exposed admin panels (phpMyAdmin, panel ports, Docker API, Redis without a password); and leaked credentials. Fix the cause, or the attacker will return.
Prevention checklist
- SSH keys only, no root password login — SSH hardening
- Firewall exposing only needed ports
- Automatic security updates
- CMS, plugins and themes updated; unused ones removed
- Databases and Redis bound to localhost or a private network
- Off-server backups you have tested — restic backups
- Monitoring for CPU, outbound traffic and site changes