How to protect ssh server from brute force attacks using fail2ban

One common attack on SSH service is brute force attacks where a remote attacker indefinitely attempts to log in with different passwords. Fail2ban is an open-source intrusion prevention framework on Linux that monitors various system log files (e.g., /var/log/auth.log or /var/log/secure) and triggers various defensive actions upon detecting any suspicious activities. You can use fail2ban to defend against brute force password guessing attacks on an SSH server.