A crypto miner on a Linux server usually shows up as CPU stuck near 100% from a process you don’t recognise. The process often runs from /tmp or /dev/shm, or from a binary that has already been deleted, and it keeps connections open to a mining pool. Find it with ps and /proc/<PID>/exe, remove its persistence (cron, systemd, ld.so.preload) before you kill it, then fix the way it got in. If it ran as root, rebuild the server.

Symptoms

  • CPU usage at or near 100% on all cores, around the clock, with no matching traffic
  • High load average, slow responses and timeouts in your apps
  • A higher cloud bill (CPU credits used up, autoscaling) or an abuse notice from your provider
  • A process with a name meant to look harmless, such as kworkerds, kdevtmpfsi, systemd-service, a random string, or just xmrig
  • CPU drops when you log in and comes back later. Some miners pause while an admin is active

Step 1: Find the process

ps -eo pid,ppid,user,%cpu,etime,args --sort=-%cpu | head -15

In top, press P to sort by CPU. Once you have a suspicious PID, ask the kernel what it really is. Process names are easy to fake; /proc is harder:

PID=12345
sudo ls -l /proc/$PID/exe          # real binary; "(deleted)" means it was removed from disk
sudo ls -l /proc/$PID/cwd          # working directory
sudo tr '\0' ' ' < /proc/$PID/cmdline; echo
sudo cat /proc/$PID/cgroup         # shows if it runs inside a container

A binary in /tmp, /var/tmp or /dev/shm, or marked (deleted), plus command-line options such as -o pool:port, --donate-level or stratum+tcp://, is a miner.

Search all processes at once:

sudo ls -l /proc/*/exe 2>/dev/null | grep -E '/tmp/|/var/tmp/|/dev/shm/|\(deleted\)'
sudo grep -la 'stratum' /proc/[0-9]*/cmdline 2>/dev/null

When top shows nothing

If the load is high but no process uses CPU, the miner may be hiding. Check for a preload rootkit and compare the PIDs in /proc with what ps reports:

cat /etc/ld.so.preload 2>/dev/null       # should not exist or be empty
diff <(ls /proc | grep -E '^[0-9]+$' | sort -n) <(ps -eo pid= | tr -d ' ' | sort -n)

A few short-lived PIDs differ naturally. A persistent one that ps never shows is being hidden.

In containers

docker stats --no-stream
docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'

A container you didn’t start, often running an image like alpine or ubuntu with a strange command, suggests someone used your Docker API.

Step 2: Check connections to mining pools

Miners talk to pools over the Stratum protocol, often on ports such as 3333, 4444, 5555, 7777 or 14444, sometimes over TLS on 443:

sudo ss -tnp state established | grep -E ':(3333|4444|5555|7777|14444)\b'
sudo ss -tnp state established | grep "pid=$PID,"

Write down the remote addresses and domains. They are useful evidence and help you block the pool at the firewall.

Step 3: Preserve evidence

Before you remove anything, save a copy of the binary. This works even if it was deleted from disk, because the kernel still holds it open:

sudo mkdir -p /root/evidence
sudo cp /proc/$PID/exe /root/evidence/miner.bin
sudo sha256sum /root/evidence/miner.bin
sudo sh -c "tr '\0' ' ' < /proc/$PID/cmdline > /root/evidence/cmdline.txt"
sudo ss -tanp | sudo tee /root/evidence/connections.txt >/dev/null

Copy the evidence off the server.

Step 4: Find and remove persistence

Miners almost always come with a way to restart: a cron job that downloads them again, a systemd service, a watchdog process, or modified SSH keys. If you kill the process first, it is often back within a minute.

First, freeze the process instead of killing it:

sudo kill -STOP $PID

Then search the usual places:

# Cron, for every user
sudo cat /etc/crontab; sudo ls -la /etc/cron.d /var/spool/cron/ 2>/dev/null
for u in $(cut -d: -f1 /etc/passwd); do sudo crontab -l -u "$u" 2>/dev/null | sed "s/^/$u: /"; done

# systemd units and timers created recently
sudo find /etc/systemd/system /usr/lib/systemd/system /lib/systemd/system \
  -type f -mtime -30 -ls 2>/dev/null
systemctl list-timers --all

# Preload and start-up scripts
cat /etc/ld.so.preload 2>/dev/null
sudo grep -rE 'curl|wget|base64' /etc/rc.local /etc/profile.d/ /root/.bashrc /root/.profile 2>/dev/null

# SSH keys added by the attacker
sudo find / -xdev -name authorized_keys -type f -exec ls -l {} \; 2>/dev/null

Look for lines that pipe curl or wget into sh, or long base64 strings. Some miners set the immutable flag on their files so you can’t delete them. Check with lsattr and remove it with sudo chattr -i <file>.

Once the persistence is removed, kill the process and delete the files:

sudo kill -9 $PID
sudo rm -f /tmp/<miner-file>

Watch CPU for the next hour. If the miner comes back, you missed something.

Step 5: Find the root cause

Removing the miner without closing the hole only buys you a few hours. The most common entry points are:

An exposed Docker API. A Docker daemon listening on TCP port 2375 without TLS gives anyone root on the host:

sudo ss -tlnp | grep -E ':(2375|2376)\b'
systemctl cat docker | grep -- '-H'
cat /etc/docker/daemon.json 2>/dev/null

Remove any tcp:// host. If you need remote access, use SSH (DOCKER_HOST=ssh://user@host) or TLS, as described in the Docker daemon security documentation.

Weak SSH passwords. Check the journal for a successful password login before the miner appeared, then switch to keys only and add fail2ban:

sudo journalctl _COMM=sshd | grep 'Accepted password'

A vulnerable or exposed application. Outdated web apps and plugins, Redis or databases open to the internet without a password, and admin panels with default credentials are all common. Check what listens publicly with sudo ss -tulpn, and check packages against known vulnerabilities, for example in the OSV database.

If the miner ran as root, or you found ld.so.preload entries or modified system binaries, don’t trust the system any more. Rebuild from a clean image, restore data from a backup taken before the intrusion, and rotate every credential that was on the server.

Prevention

  • SSH with keys only, no root password login, fail2ban on
  • Docker API never on TCP without TLS. Databases and Redis bound to 127.0.0.1, and published Docker ports filtered in DOCKER-USER
  • Automatic security updates, and regular updates of your apps and container images
  • noexec on /tmp and /dev/shm where your software allows it
  • Alerts for sustained high CPU, new processes from temp folders and new outbound connections

How Avanguard helps

  • Avanguard detects crypto-miners and programs running from temp folders or deleted files. CPU at 95% brings the full hourly scan forward.
  • It detects library preload (a rootkit sign), changes to scheduled tasks and system files, new users and new SSH keys.
  • It checks the connections of the host and its containers against threat intelligence feeds (abuse.ch, Spamhaus DROP), and reports packages with known vulnerabilities, SSH password login and services listening on all interfaces.

The agent detects and explains. It does not remove anything for you. See server attack protection.

Summary

  • Find the top CPU process and check /proc/<PID>/exe, cwd and cmdline
  • Look for binaries in /tmp, /dev/shm or marked (deleted), and for Stratum connections
  • Copy the binary and connection list as evidence
  • kill -STOP, remove cron, systemd, preload and SSH key persistence, then kill
  • Close the entry point: Docker API, SSH passwords, vulnerable apps
  • Rebuild if it ran as root, and rotate credentials
  • Add monitoring so you notice next time within minutes, not weeks