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.
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
sudoaccess - 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:
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.
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.
sudo apt update
curl -s https://install.crowdsec.net | sudo sh
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:
apt-cache policy crowdsec
The Candidate line should point to the packagecloud repository.
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).
sudo apt install -y crowdsec
sudo systemctl status crowdsec --no-pager
sudo cscli version
sudo cscli collections list
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.
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.
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:
sudo apt reinstall -y crowdsec-firewall-bouncer-nftables
sudo systemctl restart crowdsec-firewall-bouncer
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.
sudo cscli collections install crowdsecurity/apache2
filenames:
- /var/log/apache2/*.log
labels:
type: apache2
Reload the engine to apply both changes:
sudo systemctl reload crowdsec
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.
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.
Verification
First, confirm the engine is reading your logs and parsing lines:
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):
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
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.
Maintenance & troubleshooting
Keep the packages and the Hub content (parsers, scenarios, collections) current:
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:
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.
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.