CrowdSec commands cheat sheet

This cheat sheet brings together the commands and settings of CrowdSec, a system that detects attacks from the server's logs and blocks the addresses they come from: installation, collections from the Hub, setting up the logs it reads, blocking and unblocking IP addresses, allowlists, and the Firewall Bouncer, the component that enforces the blocks in the firewall. You can search for a command, filter by topic, and copy it with one click.

Installing and first checks

  • curl -s https://install.crowdsec.net | sudo sh

    Adds the official CrowdSec repository to the server. Copy the current command from the installation page in the CrowdSec documentation, and review the script before you run it.

  • sudo apt install crowdsec

    Installs the Security Engine, the component that reads the logs and detects attacks, on Ubuntu and Debian.

  • sudo dnf install crowdsec

    Installs the Security Engine on RHEL-family distributions, such as AlmaLinux and Rocky Linux, and on Fedora.

  • sudo systemctl status crowdsec

    Shows whether the service is running, along with its latest messages.

  • sudo cscli version

    Shows the installed version of CrowdSec.

  • sudo cscli setup

    Detects the services running on the server, such as SSH and a web server, and offers to install the collections and log settings that fit them.

  • sudo cscli metrics

    Shows a summary of the activity: which logs are read, how many lines were parsed, which scenarios were triggered, and which decisions were made. Same as cscli metrics show.

Hub and collections

  • sudo cscli hub update

    Downloads the latest list of items in the Hub, the CrowdSec repository of parsers, scenarios, and collections.

  • sudo cscli hub upgrade

    Upgrades all installed items to their latest version. After the upgrade, restart the service with sudo systemctl restart crowdsec.

  • sudo cscli hub list

    Lists all installed items and their status, for example whether an update is available or whether they were changed locally (tainted).

  • sudo cscli collections list

    Lists the installed collections. A collection is a bundle of parsers and scenarios for a specific service.

  • sudo cscli collections install crowdsecurity/linux

    The base collection for a Linux server: syslog parsing, geographic data on IP addresses, SSH protection, and a list of legitimate crawlers that won't be blocked.

  • sudo cscli collections install crowdsecurity/sshd

    Detects password guessing over SSH. The main scenario in the collection is crowdsecurity/ssh-bf.

  • sudo cscli collections install crowdsecurity/nginx

    Parses nginx logs and detects scans and attacks on websites. For an Apache server, the collection is crowdsecurity/apache2.

  • sudo cscli collections install crowdsecurity/wordpress

    Detects password guessing on the WordPress login page, attempts to read wp-config.php, user enumeration, and WordPress scans. Install it together with the collection for your web server.

  • sudo systemctl reload crowdsec

    Reloads the configuration after you install or remove Hub items, without stopping the service.

  • sudo cscli collections inspect crowdsecurity/sshd

    Shows the details of a collection: its items, its version, and whether it was changed locally.

  • sudo cscli collections remove crowdsecurity/apache2

    Removes a collection you don't need, for example one for a service that doesn't run on the server. The --purge option also deletes the downloaded files.

  • sudo cscli collections install crowdsecurity/sshd --force

    Reinstalls a collection marked as tainted and restores its files to the Hub version. Caution: local changes to these files are deleted.

  • sudo cscli parsers list

    Lists the installed parsers, the components that break each log line into fields such as IP address, user, and time.

  • sudo cscli scenarios list

    Lists the installed scenarios, the rules that detect an attack pattern, for example how many failed attempts come from the same address within a short time.

Log setup (acquisition)

  • /etc/crowdsec/acquis.d/

    The folder for the settings of the logs CrowdSec reads, with one YAML file per service. The general settings are in the /etc/crowdsec/acquis.yaml file. Set up each log in one place only; otherwise, its lines are read twice.

  • printf 'source: file\nfilenames:\n - /var/log/nginx/*.log\nlabels:\n type: nginx\n' | sudo tee /etc/crowdsec/acquis.d/nginx.yaml

    Creates a setting for the nginx logs. The type field determines which parser handles the lines, so it must match the installed collection.

  • printf 'source: file\nfilenames:\n - /var/log/httpd/*log\n - /var/log/apache2/*.log\nlabels:\n type: apache2\n' | sudo tee /etc/crowdsec/acquis.d/apache2.yaml

    A setting for the Apache logs: the httpd folder on RHEL-family distributions, and the apache2 folder on Ubuntu and Debian.

  • printf 'source: file\nfilenames:\n - /var/log/auth.log\n - /var/log/secure\nlabels:\n type: syslog\n' | sudo tee /etc/crowdsec/acquis.d/sshd.yaml

    A setting for the SSH login log: auth.log on Ubuntu and Debian, and secure on RHEL-family distributions. For these logs, the type is syslog.

  • printf 'source: journalctl\njournalctl_filter:\n - "_SYSTEMD_UNIT=sshd.service"\nlabels:\n type: syslog\n' | sudo tee /etc/crowdsec/acquis.d/sshd-journal.yaml

    Reads the SSH log from journald, on a server where the log isn't written to a file. On Ubuntu and Debian, the service name is ssh.service.

  • poll_without_inotify: true

    An extra line in a log setting, for when CrowdSec doesn't pick up new lines in the file, for example in a shared folder. The file is then checked at fixed intervals, and CPU usage per file goes up.

  • sudo crowdsec -t && sudo systemctl restart crowdsec

    Checks that the configuration is valid, and only if it is, restarts the service. Run it after every change to the log settings.

  • sudo cscli metrics show acquisition

    Shows, for each log, how many lines were read, how many were parsed, and how many weren't. A log that doesn't appear in the table isn't read at all.

  • sudo ls -la /etc/crowdsec/acquis.d/

    Lists the log setting files in the folder. To view the general settings, run sudo cat /etc/crowdsec/acquis.yaml.

Testing a log line with explain

  • sudo cscli explain --log "Nov 30 10:15:02 web1 sshd[1234]: Failed password for root from 198.51.100.7 port 52211 ssh2" --type syslog

    Shows how a single line goes through every parsing stage, and which parser accepted or rejected it. This is how you check whether a given line will be detected.

  • sudo tail -n 10 /var/log/nginx/access.log | sudo cscli explain -f - --type nginx -v

    Checks the last ten lines of the log, with details of every change. Don't run this check on an entire large log.

  • sudo tail -n 50 /var/log/auth.log | sudo cscli explain -f - --type syslog --failures

    Shows only the lines that weren't parsed, out of the last 50. When all the lines fail, the type is wrong or the log format doesn't match the collection.

Decisions: blocking and unblocking IP addresses

  • sudo cscli decisions list

    Lists the active decisions: the address, the decision type, the scenario that caused it, and the time left.

  • sudo cscli decisions list -i 198.51.100.7

    Shows whether a specific address is blocked, and by which scenario.

  • sudo cscli decisions list -a

    Also shows the addresses received from the Community Blocklist.

  • sudo cscli decisions add --ip 198.51.100.7 --duration 24h --reason "manual ban"

    Blocks an address manually for 24 hours. Without --duration, the block lasts four hours, and without --type, the decision type is ban.

  • sudo cscli decisions add --range 198.51.100.0/24 --duration 4h

    Blocks an entire network in CIDR notation.

  • sudo cscli decisions add --ip 198.51.100.7 --type captcha

    A captcha decision: the visitor is asked to pass a CAPTCHA check instead of being blocked. Only remediation components for web servers support it, and the Firewall Bouncer enforces ban only.

  • sudo cscli decisions delete -i 198.51.100.7

    Unblocks an address and deletes all the decisions on it.

  • sudo cscli decisions delete --id 42

    Deletes a single decision by its number, as shown in cscli decisions list.

  • sudo cscli decisions delete --all

    Deletes all decisions. Caution: attackers' addresses are unblocked too.

Alerts

  • sudo cscli alerts list

    Lists the latest alerts: the address, the scenario that detected it, and the time.

  • sudo cscli alerts list -s crowdsecurity/ssh-bf --since 24h

    Lists the alerts of a specific scenario from the last 24 hours.

  • sudo cscli alerts inspect 123 -d

    Shows the full details of an alert by its number, including the log lines that triggered it.

Allowlists: addresses that won't be blocked

  • sudo cscli allowlists create admins -d "admin addresses"

    Creates an allowlist, a list of addresses that won't be blocked. This is the method the documentation recommends for IP addresses and networks.

  • sudo cscli allowlists add admins 203.0.113.10 -d "office"

    Adds an address to the list, with a comment. The change takes effect immediately, without a restart.

  • sudo cscli allowlists add admins 203.0.113.25 -e 24h

    Adds an address for a limited time, for example for an outside contractor working on the server.

  • sudo cscli allowlists check 203.0.113.10

    Checks whether an address is on one of the lists.

  • sudo cscli allowlists inspect admins

    Shows all the addresses on the list, with their comments and expiration times.

  • sudo cscli allowlists remove admins 203.0.113.25

    Removes an address from the list.

  • /etc/crowdsec/parsers/s02-enrich/

    The folder for parser whitelists: YAML files that filter events by pattern, for example a specific URL. After changing them, restart the service. For IP addresses and networks, use allowlists.

Simulation mode

  • sudo cscli simulation status

    Shows which scenarios run in simulation mode, in which alerts are created but the addresses aren't blocked.

  • sudo cscli simulation enable crowdsecurity/ssh-bf

    Moves a single scenario to simulation mode, for example to test a new scenario before it blocks visitors.

  • sudo cscli simulation disable crowdsecurity/ssh-bf

    Returns the scenario to normal operation, with blocking.

  • sudo cscli simulation enable --global

    Moves all scenarios to simulation mode. The sudo cscli simulation disable --global command reverses this.

Firewall Bouncer: blocking in the firewall

  • sudo iptables -V

    Checks which firewall mechanism the server runs. If the output shows nf_tables, install the nftables version.

  • sudo apt install crowdsec-firewall-bouncer-nftables

    Installs the Firewall Bouncer on Ubuntu and Debian: the remediation component that blocks, in the firewall, the addresses CrowdSec decided to block. The installation registers it with the Local API automatically.

  • sudo dnf install crowdsec-firewall-bouncer-nftables

    Installs the Firewall Bouncer on RHEL-family distributions and on Fedora. For an iptables-based firewall, the package is crowdsec-firewall-bouncer-iptables.

  • /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml

    The Firewall Bouncer configuration file. Write changes that must survive a package update in the crowdsec-firewall-bouncer.yaml.local file, in the same folder.

  • mode: nftables

    The mechanism the component blocks with: nftables or iptables, or ipset for a mode in which it only manages the address lists.

  • deny_action: DROP

    The action for traffic from a blocked address: DROP ignores it, and REJECT refuses it with an error message.

  • iptables_chains: [INPUT, DOCKER-USER]

    In iptables mode, the component filters only the INPUT chain by default. When Docker containers publish ports, add DOCKER-USER too; otherwise, blocked addresses still reach them.

  • sudo systemctl enable --now crowdsec-firewall-bouncer

    Starts the component and sets it to start with the server. After changing its settings, run sudo systemctl restart crowdsec-firewall-bouncer.

  • sudo systemctl status crowdsec-firewall-bouncer

    Shows whether the component is running, along with its latest messages.

  • sudo nft list table ip crowdsec

    Shows the table the component creates in nftables, with the blocked addresses. For IPv6 addresses, the table is ip6 crowdsec6.

  • sudo ipset list crowdsec-blacklists

    In iptables mode, shows the list of blocked IPv4 addresses. The IPv6 list is crowdsec6-blacklists.

  • sudo tail -f /var/log/crowdsec-firewall-bouncer.log

    Shows the component's log in real time, for example new blocks and errors connecting to the Local API.

Remediation components, machines, and the Local API

  • sudo cscli bouncers list

    Lists the registered remediation components. The table also shows when each component last pulled the decision list, and an old time points to a component that isn't running.

  • sudo cscli bouncers add my-bouncer

    Registers a new remediation component and shows its API key, which you copy into the component's settings. The Firewall Bouncer is already registered during installation.

  • sudo cscli bouncers delete my-bouncer

    Deletes a remediation component, and its key stops working.

  • sudo cscli machines list

    Lists the machines that report to the Local API. On a single server, only the local machine appears.

  • sudo cscli lapi status

    Checks that the Local API is available and that authentication with it works. The Local API is the component that receives the alerts and passes the decisions to the remediation components.

  • sudo cscli capi status

    Checks the connection to the CrowdSec Central API, through which the Community Blocklist is received.

Console: central management (optional)

  • sudo cscli console enroll YOUR-ENROLL-KEY

    Connects the server to the CrowdSec Console, a web interface for viewing the alerts of several servers in one place. Copy the key from your Console account. The connection isn't required for CrowdSec to work.

  • sudo cscli console status

    Shows which sharing options with the Console are enabled.

Logs and troubleshooting

  • sudo tail -f /var/log/crowdsec.log

    Shows the CrowdSec log in real time.

  • sudo grep -E "level=(error|fatal)" /var/log/crowdsec.log

    Shows only the errors in the log.

  • sudo journalctl -u crowdsec -n 50 --no-pager

    Shows the last 50 messages of the service in systemd. When a configuration file is invalid, the service stops before it writes to its own log, and the error appears only here.

  • sudo grep whitelisted /var/log/crowdsec.log

    Shows alerts that were canceled because the address is on the list of allowed addresses, for example Cloudflare addresses.

What CrowdSec is and how it works

CrowdSec is made up of two parts. The Security Engine reads the logs of the services on the server, parses each line with parsers, and detects attack patterns with scenarios, such as password guessing over SSH or a website scan. When a scenario is detected, an alert and a decision are created, for example a temporary block of the address. The Remediation Components, also called bouncers, are the enforcement components: the Firewall Bouncer blocks the addresses in the firewall, and there are other components for web servers. Parsers and scenarios come from the CrowdSec Hub in bundles called collections, and you manage the whole system from the command line with cscli.

The Community Blocklist

When a scenario is detected, the server sends a signal to the CrowdSec Central API with the scenario name and version, the time, the server's ID, and the attacking IP address, including its geographic location when it's known. The signals from all participants build the Community Blocklist, with addresses identified as attackers on many servers. Each server receives the addresses that match the scenarios installed on it, so addresses that have already attacked other servers are blocked in advance. Only signals from unmodified Hub scenarios go into the list.

CrowdSec, fail2ban, and CSF

fail2ban reads the logs and blocks addresses in the firewall according to filters and jails set up on the server. CSF is a complete firewall, and its LFD detects failed login attempts. CrowdSec separates detection from enforcement, gets ready-made scenarios from the Hub, and adds the Community Blocklist to the local blocks.

How not to lock yourself out

  • An allowlist for your admin addresses: add the static address you connect to the server from, for example your office address, to an allowlist. The change takes effect immediately.
  • Unblocking a blocked address: the sudo cscli decisions delete -i command with the address removes the block. If your SSH access was blocked, connect from another address or from the server console, unblock the address, and add it to an allowlist.
  • A new scenario in simulation mode: run a scenario that hasn't been tested yet in simulation mode first, and check in cscli alerts list which addresses it would have blocked.
  • A website behind Cloudflare: the access logs show Cloudflare addresses instead of the visitors' addresses. Cloudflare ranges are excluded from blocking by default, so a whole website won't be blocked, but the attacker isn't detected either. Set up the web server to log the visitor's address from the CF-Connecting-IP header, as described in Common Cloudflare errors, and don't remove the exclusion. Traffic that goes through Cloudflare reaches the server from Cloudflare addresses, so the Firewall Bouncer doesn't block it. To block that traffic, you need a remediation component for the web server or a block in Cloudflare itself.

Common problems

  • No alerts despite attacks in the log: check with sudo cscli metrics show acquisition that the log is read and its lines are parsed. When the log doesn't appear, the path in the setting is wrong. When the lines aren't parsed, the type doesn't match, and cscli explain shows at which stage the line is rejected.
  • An alert but no block: check with cscli decisions list that a decision was created, with cscli simulation status that the scenario isn't in simulation mode, and with cscli allowlists check that the address isn't excluded. Then check with cscli bouncers list that the remediation component pulls decisions, and with systemctl status crowdsec-firewall-bouncer that it's running.
  • The Local API isn't available: an error such as connection refused on 127.0.0.1:8080 means the service isn't running, or that the address in the local_api_credentials.yaml file doesn't match the listen_uri setting in the config.yaml file. Check with sudo systemctl status crowdsec and sudo cscli lapi status.
  • An item marked as tainted: a Hub item whose files were changed on the server. It isn't upgraded automatically, and its signals aren't taken into account in the Community Blocklist. Reinstalling it with --force restores it to the Hub version, and to keep a local change, create a separate file of your own.

The IP addresses on this page, such as 203.0.113.10 and 198.51.100.7, belong to ranges reserved for documentation, so replace them with your real addresses. Log paths and service names vary between distributions, so check them on your server before you copy a setting.

Did you know?

On a Linux VPS, you connect over SSH with full root access, and install and set up CrowdSec with all the commands on this page: collections for the services on your server, log setup, allowlists, and firewall blocking with the Firewall Bouncer.

Linux VPS plans

CrowdSec FAQ

What is CrowdSec, and how is it different from fail2ban?

CrowdSec is a system that reads the server's logs, detects attacks such as password guessing or website scans, and blocks the addresses they come from. Like fail2ban, it bases its detection on the logs. The difference is that in CrowdSec, detection and enforcement are separate components, the scenarios come ready-made from the Hub, and the server also receives the Community Blocklist, with addresses that have already attacked other servers.

What is the Community Blocklist?

The Community Blocklist is a list of IP addresses identified as attackers on many servers that use CrowdSec. Each participating server sends a signal with the scenario name, the time, the server's ID, and the attacker's address, and receives in return the addresses that match the scenarios installed on it. This way, attackers' addresses are blocked even before they reach the server. The sudo cscli decisions list -a command also shows the addresses from the list.

How do I unblock an IP address in CrowdSec?

Run sudo cscli decisions delete -i with the address, and all the decisions on it are deleted. Before that, the sudo cscli decisions list -i command with the address shows whether it's blocked and by which scenario. To keep the address from being blocked again, add it to an allowlist with sudo cscli allowlists add.

How do I check that CrowdSec reads the server's logs?

The sudo cscli metrics show acquisition command shows, for each log, how many lines were read and how many of them were parsed. To check a specific line, run sudo cscli explain with the line and the log type, and see which parser detected it. Add a log that's missing from the table in a new file in the /etc/crowdsec/acquis.d folder.

Does CrowdSec work for a website behind Cloudflare?

Yes. Cloudflare's address ranges are excluded from blocking by default, so the website won't be blocked by mistake. For CrowdSec to detect the attacker itself, set up the web server to log the visitor's address from the CF-Connecting-IP header. The settings for Apache, nginx, and LiteSpeed are described on the Common Cloudflare errors page.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement