Some unexpected behaviour on a Linux server could be a result of malware infection, while other malicious software might not alert to their presence. Scanning your system for different types of unwanted programs can help identify issues, or at least give you the peace of mind for having a clean server.
There are multiple options for making sure your cloud server is clean of any malware, this guide goes over a couple of scanning software you can utilise for checking your system.
ClamAV is a popular open source antivirus engine available on multitude of platforms including the majority of Linux distributions. Install it on CentOS 7 with the following command
sudo yum install clamav clamav-update clamav-scanner-systemd clamav-server-systemd
Afterwards you’ll need to edit the configuration a little by commenting out the Example text from two files, the simplest way to do so is to use sed for some fast editing with the these commands
sudo sed -i -e "s/^Example/#Example/" /etc/freshclam.conf sudo sed -i -e "s/^Example/#Example/" /etc/clamd.d/scan.conf
With the required modules installed and configured, next you should update the virus database for ClamAV by running the updater application with
When you’ve finished updating the virus definitions, do a test scan to your home directory just to make sure the scanning works as it should, use the following command
sudo clamscan -r /home
Granted that your home directory didn’t contain any viruses or other type of malware, the scan should come back empty.
So how do you know it works?
For this, you can download an anti-virus test file, which is a small completely harmless program that most anti-virus software report as infected, though with an obvious test file name EICAR-AV-Test. Use the following command to download the test file to your home directory.
wget -P ~/ http://www.eicar.org/download/eicar.com
Now scan your home folder again with the same command as above, you should receive notice of one infected file at the end summary after the scan is completed. When you’ve confirmed that ClamAV finds the test file correctly, use the command below to scan it again and remove the infected file once found.
sudo clamscan --infected --remove --recursive /home
Be careful when using the –remove parameter. First run a broader scans without it, and then more localized scan when removing files, or remove them manually.
To perform a complete scan of your cloud server, use the this command
sudo clamscan --infected --recursive --exclude-dir="^/sys" /
The scan goes through each directory in your system root recursively, but skips /sys just to avoid unnecessary warning printouts, as the virtual file system consists of some unreadable files, which could not contain viruses anyway.