{"id":1539,"date":"2018-11-30T00:18:26","date_gmt":"2018-11-29T21:18:26","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1539"},"modified":"2024-03-11T20:20:26","modified_gmt":"2024-03-11T17:20:26","slug":"how-to-protect-ssh-server-authentication-with-fail2ban-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-protect-ssh-server-authentication-with-fail2ban-on-ubuntu-18-04\/","title":{"rendered":"How to Protect SSH Server Authentication with Fail2ban Ubuntu 18.04"},"content":{"rendered":"\n

Hello there. Welcome to our tutorial on how to protect SSH server authentication with fail2ban on Ubuntu 18.04.<\/p>\n\n\n\n

Fail2ban<\/a> is intrusion prevention tool written in Python programming language to protect servers or any service that requires authentication from brute-force attacks. Fail2ban scans the server\/service logs for any abnormally and ban any malicious IP associated with it. For example multiple SSH failed login attempts.<\/p>\n\n\n\n

It achieves this by adjusting the firewall rules to reject any further attempt by the malicious host to authenticate to the same system or a service for a defined period of time. It can also be configure to sent notifications on the same.<\/p>\n\n\n\n

As much as fail2ban mitigates such malicious issues as brute-forcing, it doesn’t alleviate any susceptibility to risks posed to your server\/service by the weak authentication mechanisms. Therefore, ensure that you implement good authentication mechanisms for your systems\/services.<\/p>\n\n\n\n

Install Fail2Ban on Ubuntu 18.04<\/h2>\n\n\n\n

Fail2ban is available on the default Ubuntu 18.04 repositories and can simply be installed by running the command below;<\/p>\n\n\n\n

sudo apt update\nsudo apt install fail2ban -y<\/pre>\n\n\n\n

Configure fail2ban<\/h2>\n\n\n\n

The configuration files for fail2ban are located under \/etc\/fail2ban<\/code> directory with jail.conf<\/code> being the main configuration file.<\/p>\n\n\n\n

In order to configure fail2ban to protect specific services, copy the jail.conf<\/code> to custom jail.local<\/code> configuration file. Direct modification of  *.conf<\/code> files  is not recommended since in case of an upgrade, they will be overwritten and changes made in them will be lost.<\/p>\n\n\n\n

Therefore, you can copy the main configuration file, jail.conf<\/code> to jail.local<\/code> and make your own customizations or you can simply create a new custom configuration and define only settings you wish to overwrite in the main .conf<\/code>.<\/p>\n\n\n\n

vim \/etc\/fail2ban\/jail.local<\/pre>\n\n\n\n

You can however use the jail.conf<\/code> to guide you on settings you would like to override.<\/p>\n\n\n\n

Fail2ban Global Settings<\/h3>\n\n\n\n

The [DEFAULT]<\/code> section of the configuration file defines settings that are applied to all the services that are protected by fail2ban. In this section, you may want to override settings like ignoreip<\/code>, bantime<\/code>, findtime<\/code>, maxretry<\/code> , destemail<\/code>, sender<\/code>, mta<\/code>, action<\/code> settings.<\/p>\n\n\n\n

To customize your jail.local<\/code>, edit it and put the following contents<\/p>\n\n\n\n

[DEFAULT]\nignoreip = 192.168.43.149\nbantime  = 1440m\nfindtime  = 5m\nmaxretry = 5\ndestemail = admin@example.com\nsender = fail2ban@<fq-hostname>\nmta = postfix<\/pre>\n\n\n\n

These parameters are described below;<\/p>\n\n\n\n