Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Security · Guide

How to Use Wordfence CLI: A Beginner's Guide

How to Use Wordfence CLI: A Beginner's Guide

Short answer

Install Wordfence CLI with pip, run the configure command to add your license key, then run malware-scan on a folder to check files or vuln-scan on a WordPress install to find vulnerable plugins and themes. Review every match before deleting anything, and schedule scans with cron.

Key takeaways

  • Wordfence CLI scans files from the server, outside WordPress.
  • It needs SSH access and a Wordfence CLI license key.
  • malware-scan checks files; vuln-scan checks plugin and theme versions.
  • A match is a lead to investigate, not proof of infection.
  • Use full paths when scheduling scans with cron.
  • The CLI complements the plugin's firewall rather than replacing it.

What is Wordfence CLI and when should you use it?

Wordfence CLI is a command-line scanner from Wordfence that checks server files for malware and WordPress installs for known vulnerabilities, without running inside WordPress itself.

The Wordfence plugin scans from inside WordPress, using PHP and your site's resources. Wordfence CLI runs directly on the server, so it can scan many sites at once, scan files outside WordPress, and keep working even when a site is broken.

That makes it useful for hosting companies, agencies and developers who manage several sites. It also helps when a hacked site will not load and the plugin cannot run a scan.

Wordfence describes the tool on its Wordfence CLI product page, and the source code and docs live in the Wordfence CLI GitHub repository.

If you only run one site and have no shell access, the regular plugin is easier. Our guide to what Wordfence does covers the plugin side.

What do you need before installing Wordfence CLI?

You need SSH or terminal access to a Linux server, a supported Python 3 version or one of the packaged builds, and a Wordfence CLI license key.

Shared hosting plans sometimes block SSH or limit how long commands can run. Check with your host before you start.

The CLI needs a license, even for free use. Wordfence offers a free license for some use cases and paid licenses for commercial or high-volume scanning, so read the Wordfence CLI license terms to choose the right one.

You also need read access to the files you want to scan. Running as the same user that owns the site files usually works; scanning other users' files may need sudo.

If you are new to the command line, our list of useful WP-CLI commands is a gentle introduction to working over SSH.

How do you install Wordfence CLI?

The simplest install for most people is through pip, the Python package manager, using the wordfence package; Wordfence also provides standalone binaries, Docker images and system packages.

To install with pip:

python3 -m pip install --user wordfence

The package is published on PyPI. Installing inside a Python virtual environment keeps it separate from system packages. The Python docs on venv explain how to create one.

python3 -m venv ~/wfcli
source ~/wfcli/bin/activate
pip install wordfence

Check the install worked:

wordfence --version

If the command is not found, the install folder is probably missing from your PATH. Use the full path inside your virtual environment or add the folder to PATH.

Some systems need extra libraries, such as a PCRE regex library, for the fastest scanning. The installation notes in the GitHub repository list current requirements for each platform.

How do you configure Wordfence CLI?

Run the configure command once to save your license key and default options, such as how many worker processes to use and where to cache signatures.

wordfence configure

The tool asks for your license key and a few preferences, then writes a configuration file in your home folder. You can also pass the license with a command-line option or environment variable, which helps in scripts.

The configuration documentation lists every setting. Most people only change the license and the worker count.

More workers scan faster but use more CPU. On a busy shared server, keep the number low so you do not slow down live sites.

How do you run a malware scan?

Run the malware-scan command followed by the folder you want to check; Wordfence CLI downloads its signatures, scans every matching file and prints any file that matches a malware signature.

wordfence malware-scan /var/www/example

To scan several sites, list several paths or point it at a parent folder. The scanner walks through subfolders automatically.

By default the tool focuses on file types where malware usually hides, such as PHP and JavaScript. Options let you include all files, exclude paths, or follow symlinks.

To save the results for later, choose an output format and file:

wordfence malware-scan --output-format csv --output-path results.csv /var/www/example

Supported formats include CSV, TSV and a human-readable format. JSON-style output and others may be available depending on version, so run wordfence malware-scan --help to see your options.

A match does not always mean infection. Some legitimate plugins use code patterns that look suspicious, so review each file before deleting it.

How do you run a vulnerability scan?

Use the vuln-scan command with the path to a WordPress install; it reads the core, plugin and theme versions and reports any with known vulnerabilities from the Wordfence database.

wordfence vuln-scan /var/www/example

The output lists each vulnerable item, its installed version and details about the issue. The fix is usually to update or remove that plugin or theme.

Vulnerability scans are much faster than malware scans because they only read version information. You can run them daily from a cron job.

Wordfence explained the feature when it launched in its post on vulnerability scanning in Wordfence CLI.

How do you read and act on the results?

Treat every malware match as a lead to investigate, compare suspicious files with clean copies, then clean or replace them and fix the hole that let the attacker in.

A practical process:

  1. Take a full backup, including the infected files, for evidence.
  2. Compare core files with a fresh WordPress download.
  3. Reinstall flagged plugins and themes from trusted sources.
  4. Check uploads folders for PHP files, which should rarely exist there.
  5. Change all passwords and security keys.
  6. Update everything flagged by vuln-scan.

Newer versions of Wordfence CLI include a remediate command that can restore known core, plugin and theme files to clean versions. Check wordfence --help to see if your version has it, and back up first.

For full clean-up steps, follow our guide on how to remove malware from WordPress.

How do you automate Wordfence CLI scans?

Schedule scans with cron on the server, write results to a file, and send an email or alert when a scan finds something.

A simple nightly cron entry might look like this:

0 3 * * * /home/user/wfcli/bin/wordfence malware-scan --output-path /home/user/scan.csv /var/www

Use full paths in cron, because cron does not load your normal shell settings. Run the command by hand first to make sure the license and paths work.

Run heavy malware scans at quiet times. Vulnerability scans are light enough to run more often.

CommandWhat it doesTypical schedule
wordfence configureSaves license and defaultsOnce
wordfence malware-scanScans files for malware signaturesNightly or weekly
wordfence vuln-scanChecks versions against known vulnerabilitiesDaily
wordfence remediate (newer versions)Restores known files to clean copiesAfter a confirmed infection
wordfence --helpLists commands and optionsAny time

Does Wordfence CLI replace the Wordfence plugin?

No, Wordfence CLI complements the plugin; it scans files and versions from the server, while the plugin adds a firewall, login protection and alerts inside WordPress.

The CLI cannot block attacks in real time. It only tells you what is already on disk.

Many site owners use the plugin for day-to-day protection and the CLI for bulk or emergency scans.

If you use the plugin, our guide to setting up the Wordfence firewall is the next step.

What are common Wordfence CLI errors and fixes?

Most Wordfence CLI errors come from a missing or invalid license, a command not found on PATH, permission problems on the files being scanned, or a failed signature download.

License errors usually mean the key was not saved or has expired. Run the configure command again and paste the key carefully, with no extra spaces.

Command not found means your shell cannot see the install folder. Activate the virtual environment, or call the tool with its full path.

Permission denied messages mean the scanning user cannot read some files. Run the scan as the site owner, or use sudo only if you understand the risk.

Signature download failures often come from a firewall blocking outbound connections from the server. Ask your host to allow access to the Wordfence servers, then try again.

Very slow scans usually come from scanning huge folders such as backups or cache directories. Exclude those paths, or scan only the web root.

If you are stuck, the issues page in the GitHub repository is a good place to check whether others have met the same error.

Frequently asked questions

Is Wordfence CLI free?

Wordfence CLI needs a license key. Wordfence offers a free license for some uses and paid licenses for commercial or high-volume scanning. Check the current license terms on the Wordfence site to see which one fits how you plan to use the scanner.

Can I use Wordfence CLI on shared hosting?

Only if your host gives you SSH access and allows Python tools and longer running commands. Many shared plans restrict this. Ask your host first, and keep worker counts low so a scan does not slow down other sites on the server.

Does Wordfence CLI remove malware automatically?

The malware scan only reports matches. Newer versions include a remediate command that can restore known WordPress core, plugin and theme files to clean copies, but you should back up first and still review custom files by hand.

How is Wordfence CLI different from the plugin scan?

The plugin scans from inside WordPress using PHP, so it needs a working site. The CLI runs on the server directly, can scan many sites and non-WordPress files at once, and works even when a site will not load.

How often should I run Wordfence CLI scans?

Vulnerability scans are light, so daily runs are reasonable. Malware scans read every file and use more CPU, so nightly or weekly runs at quiet times suit most servers. Run an extra scan after any suspected compromise.

Sources

  1. Wordfence CLI Wordfence
  2. wordfence-cli repository GitHub
  3. wordfence package PyPI
  4. Wordfence CLI configuration GitHub
  5. Vulnerability scanning in Wordfence CLI Wordfence
  6. venv: creation of virtual environments Python documentation

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

Written and checked byWPLegible Editorial Team Independent WordPress reviews and guides

Researched from the primary sources listed above and checked against our editorial rules before publishing.