Install

sudo apt install fail2ban
sudo systemctl enable fail2ban

Configure

# /etc/fail2ban/jail.local
[sshd]
enabled = true
port = 22
maxretry = 3
bantime = 3600
findtime = 600

Check Status

sudo fail2ban-client status sshd
sudo fail2ban-client unban IP_ADDRESS