Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Last active March 18, 2024 18:57
Show Gist options
  • Save gilangvperdana/c54d9cd590e788a326bdc13d39dc06d8 to your computer and use it in GitHub Desktop.
Save gilangvperdana/c54d9cd590e788a326bdc13d39dc06d8 to your computer and use it in GitHub Desktop.
Fail2ban on Ubuntu Server 20.04

General

Protect your Ubuntu Server with Fail2ban

Installation

apt install -y fail2ban

Check Status Ban

  • Default jail name is sshd
sudo fail2ban-client status sshd

Ban Manually

sudo fail2ban-client -vvv set sshd banip x.x.x.x

Unban

fail2ban-client set sshd unbanip x.x.x.x

Default configuration

  • Default retry -> max 5
  • Default jail perido -> 10 m

Create notification to Telegram

  • Configure on /etc/fail2ban/jail.conf add this on existing configurar
[sshd]
action  = iptables[name=SSH, port=22, protocol=tcp]
          telegram
  • Create script on sudo mkdir /etc/fail2ban/scripts/ then create script fail2ban-telegram.sh -> script
  • Create script on /etc/fail2ban/action.d/ then create script telegram.conf -> script
  • Reference

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment