Right-Click Virus Scan in Ubuntu: Scan Files and Auto-Quarantine with ClamAV
Scanning downloaded files manually or running a weekly scheduled scan is a great habit on Linux, especially if you frequently download archives or share files with Windows users. However, if you want your system to catch malicious files the very second they land in your Downloads folder—without you having to run a command or right-click a file—you can enable ClamAV On-Access Scanning (clamonacc).
In Ubuntu 24.04 LTS, clamonacc runs quietly in the background as a systemd service, watching your Downloads folder in real time and automatically moving any detected threats into a locked quarantine directory. Here is the complete step-by-step guide to setting it up cleanly without service errors.
Before configuring real-time scanning, ensure that ClamAV and its background daemon are installed and that your quarantine and log directories exist. Open your terminal (Ctrl + Alt + T) and run:
Next, tell the ClamAV daemon which folder to monitor and exclude the clamav system user so the scanner does not get trapped in an infinite scanning loop.
Open the ClamAV configuration file in Nano:
Scroll to the very bottom of the file and add the following lines (replace yourusername with your actual Ubuntu username):
OnAccessIncludePath: Watches your Downloads folder in real time (avoid setting this to / on desktop systems, as scanning system files continuously can slow down your PC).
OnAccessPrevention false: Allows files to be written to disk first so clamonacc can inspect them and move threats to quarantine without freezing your browser.
OnAccessExcludeUname clamav: Critical setting—without this line, clamonacc will refuse to start (status=2/INVALIDARGUMENT) to prevent infinite scanning loops.
OnAccessMaxFileSize 5M: Keeps real-time scanning snappy for everyday downloads while letting you use manual or right-click scans for large ISO or video files.
Save and exit Nano: Press Ctrl + O, hit Enter, and press Ctrl + X.
Restart the ClamAV daemon to apply your changes:
Ubuntu 24.04 does not enable the clamonacc background service out of the box, so creating a dedicated systemd service ensures real-time protection starts automatically every time you boot your computer.
Create a new systemd service file:
Paste the following configuration into the editor:
--fdpass: Passes file descriptors directly to clamd, allowing it to scan files inside your private /home directory smoothly.
--move=/var/quarantine: Automatically isolates any detected threat in your quarantine folder.
Save and close Nano (Ctrl + O → Enter → Ctrl + X).
Reload systemd, enable autostart, and launch the real-time scanner:
Check that all three core ClamAV services (clamav-daemon, clamav-freshclam, and clamonacc) are active:
If everything is configured properly, the terminal will output active three times. You can also inspect the detailed service status with systemctl status clamonacc and look for active (running) in green along with ClamInotif: watching '/home/yourusername/Downloads'. (Press q to exit the status view).
You can safely verify that clamonacc catches and quarantines threats automatically using the industry-standard, harmless EICAR antivirus test string:
Create a test file directly inside your Downloads folder:
Wait 1–2 seconds and check your quarantine folder:
You will see that eicar-test.txt disappeared from Downloads automatically and is now isolated inside /var/quarantine. To clean up the test file afterwards, remove it with sudo rm /var/quarantine/eicar-test.txt.