Home / Guides

Server guide

How to Detect and Remove a Crypto Miner on Linux

This guide is for VPS, dedicated and cPanel admins who want to protect their servers from hidden mining activity. You will learn how to identify a miner, stop it, and prevent future infections.

7 min readUpdated November 2026 by the RootManage teamWorks on Ubuntu, Debian, AlmaLinux and Rocky unless noted

The short answer

Check for unusual CPU usage, unfamiliar binaries, and high network traffic. Use tools like top, ps, netstat, and file integrity checks to confirm a miner, then kill the process and remove the files.

What is a crypto miner and why it matters

A crypto miner is software that uses a server’s CPU or GPU to solve complex mathematical problems in exchange for cryptocurrency rewards. When hidden on a Linux server, it can run silently in the background, consuming CPU, memory, and network bandwidth while generating little or no visible output. This hidden activity can degrade the performance of legitimate applications, increase power consumption and hardware wear, and may trigger alerts from monitoring systems that detect unusually high CPU usage or network traffic.

The impact extends beyond performance loss. Attackers often install miners as a stepping stone for further compromise, using the same host to host malicious payloads or to create a botnet. A compromised server can also be used to mine for a competitor’s cryptocurrency, effectively stealing the business’s resources. Additionally, the increased load can cause overheating and shorten the lifespan of hardware components, leading to costly replacements.

How to check for hidden miners

To spot a hidden crypto miner you first look at CPU usage. Run top or htop and watch for processes that stay above 80% on a single core for extended periods. A miner will often run as a non‑root user and may use a name that looks like a system daemon but has no documentation. Next, list all binaries in the system’s PATH and compare them to the list of known legitimate programs. Use find / -type f -executable -printf '%p %m %u %g %k\n' 2>/dev/null | sort -k6 -nr | head -n 20 to spot large, recently modified executables that are not part of your normal stack. Finally, check network activity: ss -tunap or netstat -tunap will show any outbound connections. A miner will often open a TCP or UDP socket to a remote mining pool IP or domain. If you see a process with high CPU, an unfamiliar binary name, and an outbound connection to an unknown host, you have a strong suspicion of a hidden miner.

terminal
# Example commands to help you identify hidden miners
# 1. Check for high CPU usage
`top -b -n 1 | grep -E '^[0-9]+ '` 
# 2. List large executables in PATH
`find $(echo $PATH | tr ':' ' ') -maxdepth 1 -type f -executable -printf '%p %k\n' | sort -k2 -nr | head -n 5` 
# 3. Inspect outbound connections
`ss -tunap | grep ESTAB | awk '{print $5}' | cut -d':' -f1 | sort | uniq -c | sort -nr | head -n 10`

When reviewing the output, look for processes that consistently use a lot of CPU, binaries that are large or have been modified recently, and connections to unfamiliar IPs or domains. These are the key indicators that a miner may be running on your server.

Steps to stop and remove the miner

To stop a crypto miner you first identify the running process. Use ps aux | grep -i miner or top to locate suspicious CPU usage. Once the PID is known, terminate it with kill -TERM <PID> and, if it resists, use kill -KILL <PID>. After the process exits, verify with ps aux | grep -i miner again to ensure it is gone. Next remove the miner files. Search for recent binaries with find / -type f -mtime -7 -exec ls -l {} + 2>/dev/null | grep -i miner. Delete each file with rm -f <path> and remove any related cron jobs or startup scripts located in /etc/cron.* or /etc/init.d/. Finally, run chkrootkit or rkhunter to scan for hidden backdoors, and review system logs for unusual entries.

terminal
# Example commands – read and adapt to your environment
# 1. Find miner processes
ps aux | grep -i miner
# 2. Terminate the process
kill -TERM <PID>
# 3. Remove miner binary
rm -f /usr/local/bin/miner
# 4. Delete related cron job

After running the cleanup, check that the CPU usage has returned to normal and that no new miner processes appear in ps or top.

What to avoid when cleaning up

When removing a crypto‑miner, avoid deleting files or directories without confirming their purpose. Blindly removing binaries from /usr/bin, /usr/local/bin or system libraries can break legitimate services and may leave the miner’s persistence scripts untouched. Do not edit configuration files such as /etc/ssh/sshd_config or /etc/crontab without first backing them up, because a syntax error can stop SSH or scheduled jobs, locking you out of the server. Always take a snapshot or full backup before making changes to system files, and verify each change with a test login or service restart.

Never disable security modules like SELinux, AppArmor, or the firewall to make cleanup easier. Turning them off reduces the system’s ability to block the miner’s re‑execution and may expose other vulnerabilities. Also, avoid installing unknown scripts or tools from untrusted sources in an attempt to “clean” the system; they can introduce new backdoors. Keep the package manager’s database intact and use the official repositories for any replacement binaries. Finally, do not reboot the server until you have confirmed that the miner processes are stopped and no residual cron jobs remain.

  • Do not delete files without confirming they belong to the miner.
  • Do not edit critical config files without a backup.
  • Do not disable SELinux/AppArmor or the firewall.
  • Do not run unverified cleanup scripts from the internet.
  • Do not reboot until you have verified the miner is stopped.
terminal
## Example: list suspicious processes and stop them safely
# List processes owned by unknown users or with high CPU usage
ps -eo pid,user,pcpu,cmd --sort=-pcpu | head -n 20
# Stop a specific miner process after confirming its PID
sudo systemctl stop miner.service   # replace with actual service name
# Disable a persistent cron job (edit after backup)
sudo crontab -e   # remove the malicious entry

After running the commands, verify that CPU usage returns to normal, that the suspicious service is no longer listed in systemctl list-units, and that the crontab no longer contains the malicious entry.

How to keep the server clean

Keeping a Linux server free from crypto miners requires continuous vigilance. Set up automated monitoring with tools such as top, htop, or glances to spot abnormal CPU usage. Configure alerts in syslog or a monitoring platform like Prometheus to notify you when a single process consumes more than a predefined percentage of CPU for a sustained period. Regularly review system logs in /var/log/ for unfamiliar binaries or repeated failed login attempts that could indicate a foothold for mining software.

Updates and hardening are the next layers of defense. Subscribe to security mailing lists for your distribution and apply updates promptly with apt update && apt upgrade or yum update. Harden the kernel by disabling unused services and enforcing a strong firewall with ufw or firewalld. Use SELinux or AppArmor profiles to limit the capabilities of web applications, and consider file integrity monitoring with tools like AIDE to detect unauthorized changes.

What to do if you suspect a repeat infection

If you suspect a repeat infection, act immediately. First, isolate the server from the network to stop further communication with malicious command‑and‑control servers. Use the firewall to block all outbound traffic except essential services, or disconnect the NIC if you can. This prevents the miner from sending data and receiving updates while you investigate. Once isolated, run a quick audit of running processes and network connections. Look for unfamiliar binaries, high CPU usage, and outbound traffic to unknown IPs. Document what you find before making any changes, and keep a snapshot of the current state for forensic purposes.

  • - Disable the network interface or block outbound traffic. - Verify running processes with ps auxf. - Check open sockets with ss -tunap. - Review system logs in /var/log for unusual entries.
terminal
# Example commands (read carefully before running)
# 1. Block all outbound traffic except SSH
sudo iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A OUTPUT -j DROP

# 2. List running processes
ps auxf | less

After running these commands, look for any processes with names like minerd, xmrig, or unfamiliar binaries in /usr/bin. Check the output of ss for connections to foreign IPs on high‑numbered ports. If you see such activity, note the PID and IP for further analysis.

When to backup or snapshot before changes

Before you start hunting for a crypto miner, create a restore point. A backup or snapshot lets you return the server to its previous state if a change breaks a service or removes a legitimate process. Small businesses often run critical web or database services; a single mis‑edit can bring a site down. By having a snapshot, you can roll back quickly and avoid downtime while you investigate further. Creating a snapshot is a low‑risk step that protects your data. Use your hosting control panel or a command line tool that supports snapshots. If you’re on a VPS, most providers offer a “take snapshot” button. On a dedicated machine, you can use LVM snapshots or simple file backups. Always verify the snapshot after creation to ensure it contains all necessary files.

terminal
# Example: create a quick file backup before making changes
sudo cp /etc/passwd /etc/passwd.bak
# Example: take an LVM snapshot (replace myvg/mylv with your volume group and logical volume)
sudo lvcreate --size 1G --snapshot --name mylv_snap /dev/myvg/mylv

If you would rather have engineers do this for you, see Linux server management, Windows server management or emergency malware cleanup.

Questions people ask

How can I tell if a process is mining cryptocurrency?

A mining process often runs with high CPU or GPU usage, uses cryptographic libraries, and may be named something generic like `python`, `node`, or `java`. Look for processes that consume 80‑90% CPU for long periods, especially if they are not part of a known application.

What files should I look for that indicate a miner?

Common miner files include hidden binaries in `/tmp`, `/var/tmp`, or user home directories, often with names like `miner`, `minerd`, or random strings. Check `/etc/cron.*` for scheduled tasks, and look for new files in `/usr/bin`, `/usr/local/bin`, or `/opt` that were added recently.

Can I use a firewall to block mining traffic?

A firewall can block outbound connections to known mining pools, but it won’t stop the CPU usage. Use firewall rules to deny traffic to IPs or domains associated with mining pools, and monitor for new outbound connections.

What tools are best for ongoing miner detection?

Tools such as `top`, `htop`, and `ps` show high CPU usage. `nethogs` or `iftop` reveal unusual traffic. For deeper analysis, `chkrootkit` or `rkhunter` can detect known miner binaries, and `auditd` can log suspicious process starts.

Want a person to look at it?

Tell us what you see. We reply with what we think is wrong and what it would take to fix it.