How to Detect and Remove Linux Mining Malware: A Step‑by‑Step Guide
This guide explains how to identify hidden cryptocurrency‑mining processes on a Linux server, stop them, disable the services that restart them, block malicious IPs, clean unauthorized SSH keys, and harden the system with tools such as sysdig, Safedog, and ClamAV.
Symptoms of a mining infection
The server shows abnormally high CPU usage (often 50%–100% on multiple cores) and memory consumption, even after a reboot. Other signs include excessive fan noise, unexplained system lag, and suspicious network connections revealed by netstat -natp.
High CPU usage shown by top or htop without any legitimate workload.
Abnormal IP addresses listed by netstat -natp.
Severe overheating and fans running at full speed.
Random system freezes.
Immediate remediation steps
1. Isolate the host and reset the root password
Disconnect the server from the network and change the root password to prevent further remote control.
2. Identify hidden mining processes
Install sysdig and unhide to reveal processes that hide from standard tools.
sudo apt install sysdig sudo apt install unhide sudo sysdig -c topprocs_cpu sudo unhide proc3. Stop the service that restarts the miner
Use systemctl status <PID> to find the associated .service unit, then stop and disable it.
systemctl stop xxxx.service
systemctl disable xxxx.service4. Kill the mining process
kill -9 <PID>After stopping the service, killing the process should bring CPU usage back to normal.
Prevent re‑infection
1. Block malicious IP addresses
netstat -natpIdentify suspicious IPs and drop them with iptables:
sudo iptables -I INPUT -s <IP> -j DROP
iptables -L INPUT -v -nPersist the rules across reboots using iptables-persistent:
sudo apt-get install iptables-persistent
sudo netfilter-persistent save
sudo systemctl enable iptables
sudo systemctl start iptables2. Remove unknown SSH public keys
cat ~/.ssh/authorized_keysDelete any keys you do not recognize.
Additional hardening tools
ClamAV – open‑source antivirus
Installation on Debian/Ubuntu:
sudo apt-get update
sudo apt-get install clamav clamav-daemonInstallation on CentOS/RHEL:
sudo yum install epel-release
sudo yum install clamav clamav-updateUpdate the virus database: sudo freshclam Common scanning commands:
# Scan a single file
clamscan /path/to/file
# Scan a directory recursively
clamscan -r /path/to/directory
# Remove infected files automatically
clamscan --remove -r /path/to/directory
# Save a scan report
clamscan -r /path/to/directory > scanreport.txt
# Show infected files while scanning
clamscan -r --bell -i /path/to/directoryDaemon‑based scanning:
sudo systemctl start clamav-daemon
clamdscan /path/to/file
clamdscan -r /path/to/directory
clamdscan --multiscan --fdpass /path/to/scanSysdig – advanced system‑monitoring tool
Install with the official one‑line script (detects the distribution and configures the repository automatically):
curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bashVerify the installation:
sysdig -pc -c topconnsResolving missing system commands for Safedog
If Safedog aborts due to missing utilities, install them as follows:
# locate command
sudo yum -y install mlocate
# lspci command
sudo yum -y install pciutils
# lsof command
sudo yum -y install lsof
# netstat command
sudo yum -y install net-tools
# killall command
sudo yum -y install psmiscCommon issues
When yum reports “No package available”, enable the EPEL repository:
sudo yum -y install epel-releaseSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
