Below is a ready-to-use script. Review and adapt variables to your environment.
#!/usr/bin/env bash set -e apt update && apt install -y fail2ban cat >/etc/fail2ban/jail.d/ssh.local <<'EOF' [sshd] enabled = true port = 22 logpath = /var/log/auth.log maxretry = 5 bantime = 3600 EOF systemctl enable --now fail2ban fail2ban-client status sshd