If you would like to know how to check wether someone is brutforcing your server to pick your ssh password, just try this command on your Debian/Ubuntu server:

journalctl -u ssh -no-pager | grep "Failed"

This could clearly show you someones attempts to login to your server. So probably you would like to secure your server not only by disabling password login to the ssh interface but also with IP blocking solution to filter out all bad actors. At this point suggested solution will be fail2ban.

To install on Debian/Ubuntu use:

apt install fail2ban

This will install initial package of the fail2ban. Test it's work by:

systemctl status fail2ban


On Ubuntu it will likely be active and running. Also make sure, that service is enabled, since this will determine wether it will be autostarted on system start or not.

On Debian it can show errors like: "Failed during configuration: Have not found any log file for sshd jail"
For this make sure you have the file /var/log/auth.log. And if not, just run this command:

touch /var/log/auth.log


Now, when fail2ban is running and active, let's make sshd secured:
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local


Edit your newly created jail.local by addint these lines in the [sshd] section:
enabled = true
maxretry = <number>
bantime = <number>

Put your own numbers of maximum retries before going to ban and time for the IP address to stay banned.

Thats it, let's restart fail2ban and check how it works:

systemctl restart fail2ban
fail2ban-client status #to check active jails
fail2ban-client status sshd #to check sshd fail2ban statistics

No comments yet