Install Fail2Ban on Ubuntu 16.04
$ sudo apt-get update
$ sudo apt-get install fail2ban
The default settings are good and for more info see the link below. With the default settings, the fail2ban service will ban a client that unsuccessfully attempts to log in 5 times within a 10 minute window.
https://www.digitalocean.com/community/tutorials/how-to-protect-ssh-with-fail2ban-on-ubuntu-14-04