Проверяем не установлен ли Fail2ban:
systemctl status fail2ban.service
Если есть, то отключаем:
systemctl stop fail2ban && systemctl disable fail2ban
Скачиваем и запускаем скрипт:
apt install curl -y && curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | bash && apt update
Если вылетает ошибка о том, что не смогли определить OS, то добавляем 2 ключа dist и os. Ниже пример для Debian 12 Bookworm:
apt install curl -y && curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | os=debian dist=bookworm bash && apt update
Ставим CrowdSec и вышибалу. Я также ставлю для Nginx. Удалить если не нужен.
apt install -y crowdsec crowdsec-firewall-bouncer-nftables crowdsec-nginx-bouncer
Запускаем настройку:
/usr/share/crowdsec/wizard.sh -c
В файле /etc/crowdsec/notifications/http.yaml производим следующие замены:
- Название хоста - Hostname
- ID-чата Телеграм
- TELEGRAM_API_KEY
nano /etc/crowdsec/notifications/http.yaml
Настроим адреса и сети, не подлежащие блокировке, т.е. белый список:
nano /etc/crowdsec/parsers/s02-enrich/whitelists.yaml
Производим замену в файле /etc/crowdsec/profiles.yaml duration: 2400h
Также раскомментируем строки notification и - http_default для уведомлений в телегу.
nano /etc/crowdsec/profiles.yaml
В обоих файлах меняем leakspeed: "3600s" и capacity: 5. Значений в файлах несколько!!!
nano /etc/crowdsec/scenarios/ssh-bf.yaml
nano /etc/crowdsec/scenarios/ssh-slow-bf.yaml
Далее:
sed -i 's/online_client/#online_client/' /etc/crowdsec/config.yaml && \
sed -i 's/credentials_path: \/etc\/crowdsec\/online/#credentials_path: \/etc\/crowdsec\/online/' /etc/crowdsec/config.yaml
Перезапускаем службы:
systemctl restart crowdsec crowdsec-firewall-bouncer
Если crowdsec-firewall-bouncer вываливается с ошибой API, то:
cscli bouncers add crowdsec-firewall-bouncer
Копируем полученный API в файл /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml и перезапускаем сервис:
systemctl restart crowdsec-firewall-bouncer
Для полного удаления из системы запускаем следующую команду:
apt-get -y autoremove crowdsec crowdsec-firewall-bouncer-nftables && \
apt-get -y purge crowdsec crowdsec-firewall-bouncer-nftables && \
apt-get -y autoremove --purge crowdsec crowdsec-firewall-bouncer-nftables