Installing fail2ban
apt-get install fail2ban
The fail2ban service keeps its configuration files in the /etc/fail2ban directory. There is a file with defaults called jail.conf.
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Installing nginx, sendmail and iptables for more security apt-get install nginx sendmail iptables-persistent
Allowing only certain ports, i.e., setting firewall
root@projectx:~# iptables -A INPUT -i lo -j ACCEPT
root@projectx:~# iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
root@projectx:~# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
root@projectx:~# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
root@projectx:~# iptables -A INPUT -j DROP
root@projectx:~# iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-N fail2ban-ssh
-A INPUT -p tcp -m multiport --dports 22 -j fail2ban-ssh
-A INPUT -i lo -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -j DROP
-A fail2ban-ssh -j RETURN
sudo nano /etc/fail2ban/jail.local
bantime = 1800 // half an hour
destemail = [email protected]
action_mwl = bans and sends email with whois log
action = %(action_mwl)s
[nginx-http-auth]
enabled = true
service fail2ban stop
service fail2ban start