Skip to content

VPS: Install CrowdSec on Linux

Install CrowdSec with the Firewall Bouncer on your Linux VPS to automatically block brute-force attacks and scanners → Learn more

26 November 20266 min read2 Views0 helpful

Introduction

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.
Important

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, the firewall, and DDoS protection: what does each do?

CrowdSec does not replace your firewall or DDoS protection. It complements both:

ProtectionWhere it worksWhat it protects against
ZAP-Hosting DDoS protectionAt the network level, before traffic reaches your VPS; active automaticallyFlooding attacks that generate large amounts of traffic
Network firewall in the ZapX dashboardIn front of your VPSPorts and rules that you configure yourself
UFW or IPTablesOn your VPSWhich ports are generally reachable
CrowdSecOn your VPSIndividual 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.

Prerequisites

  • 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:

Code
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl
Warning

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.

Install CrowdSec

Add the package repository

CrowdSec provides its own package repository, which always contains the latest version. Add it with this command:

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

Then check which repository the version comes from:

Code
apt-cache policy crowdsec
Info

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.

Install the Security Engine

Code
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:

Code
sudo cscli collections list

The list should include at least crowdsecurity/linux. It includes detection for SSH brute-force attacks.

Install the Firewall Bouncer

The Firewall Bouncer is available in two versions: for nftables and for iptables. Check which one your system uses with this command:

Code
sudo iptables -V
  • If the output contains nf_tables or iptables isn't installed, use the nftables version:
Code
sudo apt install -y crowdsec-firewall-bouncer-nftables
  • If the output contains legacy, use the iptables version:
Code
sudo apt install -y crowdsec-firewall-bouncer-iptables

The Bouncer automatically registers with CrowdSec during installation. Check that it is connected:

Code
sudo cscli bouncers list

The Bouncer uses its own rules and is compatible with UFW. Your existing UFW or IPTables rules remain unchanged.

Check that CrowdSec is working

Which logs are being read?

Code
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.

View current decisions

Code
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.

Test a block manually

You can test a block without waiting for an attack. The IP address in this example is for demonstration purposes only:

Code
sudo cscli decisions add --ip 203.0.113.10 --duration 5m
sudo cscli decisions list
sudo cscli decisions delete --ip 203.0.113.10
Warning

Never test with your own IP address Otherwise, you'll block yourself and won't be able to access your server over SSH.

Allowlist your own IP addresses

If you have a fixed IP address, such as at your office, you can permanently exclude it from blocks:

Code
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.

Tip

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.

Protect a web server (nginx or Apache)

If your VPS runs a web server, CrowdSec can also detect scanners and bots looking for vulnerabilities. Install the appropriate collection:

For nginx:

Code
sudo cscli collections install crowdsecurity/nginx

For Apache:

Code
sudo cscli collections install crowdsecurity/apache2

Then reload CrowdSec:

Code
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):

Code
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.

Warning

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.

Using Fail2Ban alongside CrowdSec

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:

Code
sudo systemctl disable --now fail2ban

Optional: CrowdSec Console

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:

Code
sudo cscli console enroll DEIN_KEY

Then confirm the server in the Console and restart CrowdSec:

Code
sudo systemctl restart crowdsec

Troubleshooting

Port 8080 is already in use

Change the port in three files, for example to 8085:

  • /etc/crowdsec/config.yaml: set listen_uri to 127.0.0.1:8085
  • /etc/crowdsec/local_api_credentials.yaml: set url to http://127.0.0.1:8085
  • /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml: set api_url to http://127.0.0.1:8085/

Then restart both services:

Code
sudo systemctl restart crowdsec crowdsec-firewall-bouncer

Installation stops with “capi register”

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:

Code
sudo dpkg --configure -a

You've locked yourself out

Connect to your VPS using the VNC console in your ZapX dashboard and remove the block:

Code
sudo cscli decisions delete --ip DEINE_IP

Where can I find the CrowdSec logs?

Code
sudo journalctl -u crowdsec -n 50
sudo journalctl -u crowdsec-firewall-bouncer -n 50

Conclusion

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! 🙂

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

Both read log files and block suspicious IP addresses. Fail2Ban only knows about attacks on your own server. CrowdSec also uses a community blocklist of IPs flagged by other users and includes ready-made detection rules for many services. Don't use both programs for the same service at the same time.
No. ZAP-Hosting's DDoS protection filters flooding attacks that generate large amounts of traffic at the network level, before the traffic reaches your VPS. CrowdSec detects individual attackers in your logs, such as brute-force logins or scanners, complementing DDoS protection.
Yes. The Security Engine and Firewall Bouncer are open source and free. The optional CrowdSec Console web interface also has a free plan.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.