21 lines
627 B
Bash
21 lines
627 B
Bash
#!/bin/bash
|
|
|
|
# update et install fail2ban
|
|
apt-get update -y && apt-get install fail2ban -y
|
|
# copie des fichiers
|
|
cp ./jail.local /etc/fail2ban/jail.local
|
|
cp ./jail.conf /etc/fail2ban/jail.conf
|
|
|
|
# recup de l'ip pour la conf
|
|
IP=$(ip route get 1.2.3.4 | awk '{print $7}')
|
|
# recup du port SSH (TODO: ajouter check si port SSH renseigné)
|
|
SSH=$(grep "^Port" /etc/ssh/sshd_config | awk '{print $2}')
|
|
|
|
# change IP et SSH port
|
|
sed -i "s/IP/"$IP"/" /etc/fail2ban/jail.local
|
|
sed -i "s/SSH_PORT/"$SSH"/" /etc/fail2ban/jail.local
|
|
|
|
# changement dbpurge tout les ans
|
|
sed -i "s/1d/365d/" /etc/fail2ban/fail2ban.conf
|
|
|
|
systemctl restart fail2ban |