geek.sonde.uk updated:
Security CrowdSec Debian 13

Install CrowdSec on Debian 13

Set up the CrowdSec Security Engine from the official repository, enforce bans at the kernel firewall with the nftables bouncer, and add Apache detection. You will finish with a working, verified setup that also receives the community blocklist.

~8 min read Debian 13 (Trixie) · Apache Difficulty: Intermediate
01

Prerequisites & how it works

CrowdSec splits detection from enforcement. The Security Engine reads your logs and decides who is hostile; a separate component, the bouncer, polls the engine's Local API and does the actual blocking. Without a bouncer, CrowdSec only raises alerts.

You will need:

  • A Debian 13 server with root or sudo access
  • Outbound HTTPS (443), used to reach the repository and the CrowdSec Central API
  • Apache writing logs under /var/log/apache2/ (for the web detection part)
  • An SSH session that is not your only way in: keep a second one open while testing

Debian 13 uses nftables as its firewall backend. Confirm it before choosing the bouncer package:

bash
sudo nft list tables
iptables --version

If iptables --version reports (nf_tables), you are on the nftables compatibility layer and the nftables bouncer is the cleaner choice.

02

Add the official repository

Debian ships its own crowdsec package, but it trails upstream, and detection rules matter as much as the binary. The official repository tracks the latest stable release. Refresh the package lists first: the script installs gnupg if missing, and that fails on stale lists.

bash
sudo apt update
curl -s https://install.crowdsec.net | sudo sh
⚠️
Piping to a root shell

If you prefer to read it first, download the script with curl -s https://install.crowdsec.net -o crowdsec-install.sh, inspect it, then run sudo sh crowdsec-install.sh. The official docs also list the manual steps (import the GPG key into /etc/apt/keyrings/ and add the repo line yourself).

Check that apt will pick the repository version and not Debian's:

bash
apt-cache policy crowdsec

The Candidate line should point to the packagecloud repository.

03

Install the Security Engine

The post-install hook runs service detection and enables a sensible set of collections automatically (typically linux, sshd and whitelist-good-actors).

bash
sudo apt install -y crowdsec
sudo systemctl status crowdsec --no-pager
sudo cscli version
sudo cscli collections list
ℹ️
SSH logs on Debian

A minimal Debian install has no rsyslog, so /var/log/auth.log may not exist and SSH events live in journald. The setup step writes the matching journalctl acquisition under /etc/crowdsec/acquis.d/ on its own, so there is nothing to fix here.

04

Install the firewall bouncer

The engine is only a smoke detector until something enforces its decisions. The nftables bouncer registers itself with the Local API (generating its own API key) and drops banned IPs at the kernel firewall.

bash
sudo apt install -y crowdsec-firewall-bouncer-nftables
sudo systemctl enable --now crowdsec-firewall-bouncer
sudo cscli bouncers list

The bouncer should be listed with a recent Last API pull timestamp. If it is missing or not authenticating, reinstall the package so it regenerates its credentials:

bash
sudo apt reinstall -y crowdsec-firewall-bouncer-nftables
sudo systemctl restart crowdsec-firewall-bouncer
05

Add Apache detection

Install the Apache collection (parsers plus scenarios for scanners, bad user agents, path traversal, brute force and more), then tell the engine which logs to read.

bash
sudo cscli collections install crowdsecurity/apache2
yaml /etc/crowdsec/acquis.d/apache2.yaml
filenames:
  - /var/log/apache2/*.log
labels:
  type: apache2

Reload the engine to apply both changes:

bash
sudo systemctl reload crowdsec
ℹ️
Custom log locations

If your virtual hosts log elsewhere (hosting panels such as Plesk keep per-domain logs outside /var/log/apache2/), add the matching paths under filenames.

🚨
Behind a reverse proxy or CDN

If Apache sits behind Cloudflare or another proxy, the logs contain the proxy's address unless the real client IP is restored (for example with mod_remoteip). Without that, CrowdSec will see, and may ban, the proxy IPs instead of the attackers. Fix the client IP in the logs before enabling web detection.

06

Verification

First, confirm the engine is reading your logs and parsing lines:

bash
sudo cscli metrics
sudo cscli capi status

Under Acquisition Metrics you should see your Apache files with lines read and parsed. The CAPI check confirms the link to the Central API, which delivers the community blocklist.

Now test enforcement end to end by banning a throwaway address (use a documentation IP, never your own):

bash
sudo cscli decisions add --ip 203.0.113.50 --duration 5m --reason "manual test"
sudo nft list ruleset | grep -i crowdsec
sudo cscli decisions delete --ip 203.0.113.50
✅
Success

If nft list ruleset shows CrowdSec tables and sets, and cscli bouncers list shows a recent pull, bans are being enforced. On a public server, real SSH brute-force alerts typically appear within minutes; check them with sudo cscli alerts list.

07

Maintenance & troubleshooting

Keep the packages and the Hub content (parsers, scenarios, collections) current:

bash
sudo apt update && sudo apt install --only-upgrade crowdsec crowdsec-firewall-bouncer-nftables
sudo cscli hub update
sudo cscli hub upgrade

Useful day-to-day commands:

bash
sudo cscli decisions list          # active bans
sudo cscli alerts list             # what triggered them
sudo cscli decisions delete --ip 1.2.3.4   # unban an IP
sudo journalctl -u crowdsec -u crowdsec-firewall-bouncer -e

If alerts appear but nothing gets blocked, check that the bouncer is running (systemctl is-active crowdsec-firewall-bouncer) and that nft list ruleset contains CrowdSec chains. If you ever lock yourself out, a decision can be removed from the console with cscli decisions delete.

⚠️
Avoid two owners of the same rules

If Fail2ban is also installed, make sure it does not manage the same chains or IPs. Overlapping firewall rules are the most common source of confusing behaviour.