CrowdSec is free, open-source security software for Linux servers. It reads your VPS log files (such as SSH or web server logs), detects attack patterns like brute-force logins or scanners looking for vulnerabilities, and automatically blocks the attacker's IP address. You also get a community blocklist: IP addresses flagged by other CrowdSec users are blocked on your server before they even try to attack it.
CrowdSec consists of two parts:
- Security Engine: reads the logs, detects attacks, and decides which IP address to block.
- Bouncer: enforces the blocks. In this guide, you'll use the Firewall Bouncer, which blocks IPs directly in the Linux firewall.
Nothing is blocked without a Bouncer The Security Engine only detects attacks and makes decisions. The Bouncer is what enforces them. Always install both parts.
CrowdSec does not replace your firewall or DDoS protection. It complements both:
| Protection | Where it works | What it protects against |
|---|---|---|
| ZAP-Hosting DDoS protection | At the network level, before traffic reaches your VPS; active automatically | Flooding attacks that generate large amounts of traffic |
| Network firewall in the ZapX dashboard | In front of your VPS | Ports and rules that you configure yourself |
| UFW or IPTables | On your VPS | Which ports are generally reachable |
| CrowdSec | On your VPS | Individual attackers identified in your logs: brute-force attacks, scanners, bots |
DDoS attacks are still filtered by DDoS protection. CrowdSec handles attacks that come through an open port and look like normal traffic to DDoS protection, such as thousands of incorrect SSH passwords.
- A VPS running Debian or Ubuntu, with root or sudo privileges.
- An SSH connection to your server. If you're not sure how to connect, see our guide First Access (SSH).
- Recommended: a configured firewall.
First, update your server and install curl if it isn't already installed:
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl
Port 8080 must be available
CrowdSec uses port 8080 internally (only on 127.0.0.1). If a service is already using port 8080 on your server, such as a web app or Docker container, this will cause a conflict. Check first by running sudo ss -tlnp | grep ':8080'. If the command returns any output, read the Port 8080 is already in use section below first.
CrowdSec provides its own package repository, which always contains the latest version. Add it with this command:
curl -s https://install.crowdsec.net | sudo sh
Then check which repository the version comes from:
apt-cache policy crowdsec
Ubuntu's own package repositories contain a very old version of CrowdSec (1.4.6). The version shown next to Candidate must be newer. If it isn't, run sudo apt update again.
sudo apt install -y crowdsec
During installation, CrowdSec detects the services on your server and downloads suitable detection rules, known as Collections. See which ones are enabled with:
sudo cscli collections list
The list should include at least crowdsecurity/linux. It includes detection for SSH brute-force attacks.
The Firewall Bouncer is available in two versions: for nftables and for iptables. Check which one your system uses with this command:
sudo iptables -V
- If the output contains
nf_tablesoriptablesisn't installed, use the nftables version:
sudo apt install -y crowdsec-firewall-bouncer-nftables
- If the output contains
legacy, use the iptables version:
sudo apt install -y crowdsec-firewall-bouncer-iptables
The Bouncer automatically registers with CrowdSec during installation. Check that it is connected:
sudo cscli bouncers list
The Bouncer uses its own rules and is compatible with UFW. Your existing UFW or IPTables rules remain unchanged.
sudo cscli metrics
Under Acquisition Metrics, you can see which log files CrowdSec is reading and how many lines it has processed. If no log files appear there, CrowdSec won't detect any attacks.
sudo cscli decisions list
On a server directly connected to the internet, the first blocked IPs usually appear here after a short time. IPs from the community blocklist aren't shown individually, but they are still blocked.
You can test a block without waiting for an attack. The IP address in this example is for demonstration purposes only:
sudo cscli decisions add --ip 203.0.113.10 --duration 5m
sudo cscli decisions list
sudo cscli decisions delete --ip 203.0.113.10
Never test with your own IP address Otherwise, you'll block yourself and won't be able to access your server over SSH.
If you have a fixed IP address, such as at your office, you can permanently exclude it from blocks:
sudo cscli allowlists create meine-ips -d "Eigene feste IP-Adressen"
sudo cscli allowlists add meine-ips DEINE_IP -d "Büro"
Replace DEINE_IP with your IP address. View the allowlist with sudo cscli allowlists inspect meine-ips.
If your home IP address changes, an allowlist probably isn't worthwhile. Instead, log in with an SSH key. Your own logins won't fail, and CrowdSec won't have a reason to block you.
If your VPS runs a web server, CrowdSec can also detect scanners and bots looking for vulnerabilities. Install the appropriate collection:
For nginx:
sudo cscli collections install crowdsecurity/nginx
For Apache:
sudo cscli collections install crowdsecurity/apache2
Then reload CrowdSec:
sudo systemctl reload crowdsec
If the web server wasn't set up when you installed CrowdSec, you also need to tell CrowdSec where to find the logs. Create the file /etc/crowdsec/acquis.d/nginx.yaml (or apache2.yaml for Apache):
filenames:
- /var/log/nginx/*.log
labels:
type: nginx
For Apache, use /var/log/apache2/*.log and type: apache2. Reload CrowdSec again, then check with sudo cscli metrics to see whether the logs appear.
A reverse proxy or CDN in front of your web server If a reverse proxy or CDN sits in front of your web server, the logs often show its IP address instead of the visitor's. CrowdSec would then block the proxy. Make sure the web server logs the visitor's actual IP address first.
Fail2Ban and CrowdSec essentially do the same thing: read logs and block suspicious IP addresses. Fail2Ban only handles attacks on your own server. CrowdSec also uses insights from the community and includes ready-made detection rules for many services.
If you set up Fail2Ban using our security tips, don't use both programs for the same service at the same time. If you want CrowdSec to replace Fail2Ban, disable Fail2Ban:
sudo systemctl disable --now fail2ban
CrowdSec's free web interface (CrowdSec Console) lets you view attacks and blocks in your browser. Create an account there, copy your enrollment key, and connect your server:
sudo cscli console enroll DEIN_KEY
Then confirm the server in the Console and restart CrowdSec:
sudo systemctl restart crowdsec
Change the port in three files, for example to 8085:
/etc/crowdsec/config.yaml: setlisten_urito127.0.0.1:8085/etc/crowdsec/local_api_credentials.yaml: seturltohttp://127.0.0.1:8085/etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml: setapi_urltohttp://127.0.0.1:8085/
Then restart both services:
sudo systemctl restart crowdsec crowdsec-firewall-bouncer
During installation, CrowdSec registers with the CrowdSec API on the internet. If installation stops with a message such as cscli capi register ... timeout, your server can't reach api.crowdsec.net. Check whether outbound traffic is blocked by your firewall or by the network firewall in the ZapX dashboard. Then complete the installation:
sudo dpkg --configure -a
Connect to your VPS using the VNC console in your ZapX dashboard and remove the block:
sudo cscli decisions delete --ip DEINE_IP
sudo journalctl -u crowdsec -n 50
sudo journalctl -u crowdsec-firewall-bouncer -n 50
CrowdSec now detects brute-force attacks and scanners on your VPS and automatically blocks attackers in the firewall. Along with DDoS protection, a firewall, and SSH key authentication, your server is well protected. If you have any questions or issues, our support team is here to help every day! 🙂