What a Scan Can and Cannot Show
Scanners compare files with signatures of known malware and look for known traces of rootkits. That finds common web shells and well-known toolkits, but not new or custom malware, and a rootkit that controls the kernel can hide from any tool on the same system. A clean result means "nothing known was found"; a hit is a lead to check, since false positives happen.
Scan Files with ClamAV
# Ubuntu, Debian
sudo apt install clamav
# AlmaLinux, Rocky Linux (from EPEL)
sudo dnf install epel-release
sudo dnf install clamav clamav-update
sudo freshclam
freshclam downloads the signature database. On Ubuntu and Debian, the clamav-freshclam service installed with the package keeps it updated, and a manual freshclam may fail while that service runs. Then scan the folders where uploads and code live:
sudo clamscan -r -i /var/www /home /tmp
sudo clamscan -r -i -l /root/clamscan.log /var/www
-r scans folders recursively, -i prints only infected files, and -l writes a log. Do not add --remove: check each hit before anything is deleted. Scans load a small server for a long time, so run regular ones from a cron job at a quiet hour.
Check for Rootkits
sudo apt install rkhunter chkrootkit # Ubuntu, Debian
sudo dnf install rkhunter # AlmaLinux, Rocky Linux (EPEL)
sudo rkhunter --propupd
sudo rkhunter --check --sk
sudo chkrootkit
--propupd records the properties of system files as a baseline; run it only on a system you trust, and again after updates. --check compares against it, and --sk skips the key presses between tests; warnings go to /var/log/rkhunter.log. Both tools also report harmless findings, so read each warning before you act.
Verify System Files with the Package Manager
The package manager knows the checksum of every file it installed. Changed binaries in /usr/bin or /usr/sbin are a strong sign of tampering:
# AlmaLinux, Rocky Linux
sudo rpm -Va
# Ubuntu, Debian
sudo dpkg --verify
sudo apt install debsums && sudo debsums -c
A 5 in the third position of an rpm -Va line, or a line from dpkg --verify or debsums -c that names a binary, means the file's content differs from the package. Changed configuration files in /etc are normal. An attacker with root can also alter the checksum database.
Audit the Configuration
sudo apt install lynis # from EPEL on AlmaLinux, Rocky Linux
sudo lynis audit system
Lynis does not look for malware; it reviews the configuration and suggests hardening steps. File-integrity tools such as AIDE record checksums of chosen files on a clean system and report every later change.
Signs of Compromise to Check by Hand
- Processes: unknown names, or programs running from
/tmpor/dev/shm; see how to list processes. - Ports and connections:
sudo ss -tulpnandsudo ss -tnp; see how to check open ports. - Scheduled jobs: every user's crontab,
/etc/cron.*, andsystemctl list-timers; see how to list cron jobs. - SSH keys: unknown lines in
authorized_keysfor root and every user. - Accounts: new users, and any account besides root with UID 0:
awk -F: '$3 == 0' /etc/passwd. - Logins and services: logins you do not recognize in
last(wtmpdb laston Debian 13) and the authentication log or the SSH journal, and unknown unit files in/etc/systemd/system.
After a Finding: Confirm, Then Rebuild
- Confirm: check the file or the warning by hand; it may be a false positive.
- Keep evidence: take a snapshot before you change anything, to find out later how the attacker got in.
- Rebuild: once a compromise is confirmed, do not try to clean the server, because you cannot prove what else was changed. Reinstall from a clean image and restore data from a backup made before the intrusion; see how to back up a Linux server.
- Rotate credentials: every password, SSH key, API key, and database password that was stored on the server or typed on it.
- Close the way in: fix the exploited software before the new server goes online.
Prevent the Next One
Most compromises start with outdated software, a weak password, or an exposed service. Turn on automatic security updates, log in with keys only, and keep tested backups; the full list is in the initial server setup checklist.