sudo apt-get install fail2ban -y
sudo systemctl enable --now fail2ban
sudo ufw allow ssh
NOTE: To allow SSH traffic into the server
Fail2ban depends on a few different files and directories, which are:
WARNING: The default values in /etc/fail2ban/jail.conf may change with package updates, so it is recommended to create a jail.local file with the configuration changes needed.
Create the jail.local file if it does not exist, otherwise edit it and populate it with:
[DEFAULT] ignoreip = 127.0.0.1/8 ::1 bantime = 1d findtime = 5m maxretry = 5 destemail = root@localhost sender = root@mediaserver
NOTE: Notice the [DEFAULT] tag.
To have these new settings, restart Fail2Ban:
sudo systemctl restart fail2ban
Create the jail.local file if it does not exist, otherwise edit it and populate it with:
sudo vi /etc/fail2ban/jail.local
…and populate that file:
[sshd] enabled = true port = ssh filter = sshd logpath = /var/log/auth.log maxretry = 3 findtime = 300 bantime = 28800 ignoreip = 127.0.0.1
NOTE:
To have these new settings, restart Fail2Ban:
sudo systemctl restart fail2ban
sudo systemctl restart fail2ban