Derived from here:
sudo apt install -y fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
sudo systemctl status fail2ban
config fail2ban for ufw
echo "[DEFAULT]" | sudo tee -a /etc/fail2ban/jail.local
echo "banaction=ufw" | sudo tee -a /etc/fail2ban/jail.local
restart the service and check
sudo systemctl restart fail2ban
sudo fail2ban-client status
sudo fail2ban-client status sshd