ClamAV is an open-source antivirus software that helps detect malware, viruses, and other harmful threats on your Linux server. In this guide, we’ll walk you through the steps to install ClamAV on a Linux system, ensuring you can scan files and keep your system secure.

Step 1: Update the package list

Before installing any software, it’s good practice to update your system’s package list. Open the terminal and run the following command:

sudo apt update

This ensures that the package manager has the latest information about available packages.

Step 2: Install ClamAV

Once the package list is updated, you can proceed with installing ClamAV. Run the following command:

sudo apt install clamav clamav-daemon
  • clamav is the main package for the antivirus engine.

  • clamav-daemon is a background service that keeps ClamAV running continuously.

The package manager will install all necessary dependencies for ClamAV.

Step 3: Update ClamAV virus definitions

ClamAV uses a signature database to detect threats. After installation, it’s essential to update the virus database to ensure protection against the latest threats. Run the following:

sudo freshclam

This will download the latest virus definitions from ClamAV servers. Make sure your internet connection is active during the update.

Step 4: Start the ClamAV daemon

To ensure ClamAV runs continuously and scans files in the background, you need to start the ClamAV daemon. Use the following command:

sudo systemctl start clamav-daemon

If you want ClamAV to start automatically at boot, run:

sudo systemctl enable clamav-daemon

Step 5: Run a virus scan

Now that ClamAV is installed and running, you can begin scanning files for potential threats. To scan a specific directory, use:

clamscan -r /path/to/directory

For example, to scan the home directory:

clamscan -r /home/username

The -r option enables recursive scanning, meaning ClamAV will scan all subdirectories within the specified directory.

Step 6: Scan and remove infected files

If ClamAV detects infected files, it will report them in the terminal output. To automatically remove infected files, use the --remove option:

clamscan -r --remove /path/to/directory

Be careful when using this option because it will delete any infected files it finds. Make sure to back up important files before running a scan with removal enabled.

Step 7: Schedule regular scans (optional)

To schedule regular scans with ClamAV, you can use cron jobs. For example, to run a daily scan at 2 AM, edit cron jobs with:

crontab -e

Then add the following line to schedule the scan:

0 2 * * * /usr/bin/clamscan -r /home/username

This will perform a daily scan of your home directory at 2 AM.

Conclusion

ClamAV is a reliable and efficient antivirus solution for Linux systems. By following these simple steps, you can easily install ClamAV, update the virus database, and begin scanning files for potential threats. Additionally, you can schedule regular scans to ensure your system remains secure at all times.