Skip to main content

How to Install and Configure Fail2ban on Linux for SSH Protection

HardReset.InfoJanuary 1, 20267 min186 views
11 connections·12 entities in this video→

Installing Fail2ban on Linux

  • πŸ’‘ Fail2ban is not installed by default on Linux and needs to be installed via the terminal.
  • πŸš€ To install, use the command sudo apt install fail2ban and confirm with 'y'.
  • βœ… After installation, verify the service status with sudo systemctl status fail2ban. If inactive, enable it using sudo systemctl enable --now fail2ban.

Fail2ban Configuration Files

  • πŸ“Œ Configuration files for Fail2ban are located in the /etc/fail2ban/ directory.
  • ⚠️ It is crucial not to edit the default configuration files directly.
  • πŸ› οΈ Instead, create a new configuration file, such as jail.local, to customize settings safely.

Configuring SSH Protection (jail.local)

  • πŸ”‘ An example SSH jail configuration includes enabled = true, port = 22, and filter = sshd.
  • πŸ”’ The logpath specifies the log file to monitor, typically /var/log/auth.log.
  • πŸ“ˆ maxretry sets the maximum failed attempts before an IP is banned (e.g., 5).
  • ⏳ bantime defines the duration of the ban in seconds (e.g., 600 seconds for 1 hour).
  • ⏱️ findtime is the time window in seconds during which failures are counted (e.g., 600 seconds for 1 hour).

Managing Fail2ban with fail2ban-client

  • πŸ”„ After configuration changes, restart Fail2ban with sudo systemctl restart fail2ban.
  • πŸ” Use fail2ban-client status to view active jails, such as sshd.
  • πŸ“Š To check the status of a specific jail, use fail2ban-client status sshd.
  • 🚫 To unban an IP address, use sudo fail2ban-client set sshd unbanip <IP_ADDRESS>.
  • βœ‹ You can also manually ban an IP address using sudo fail2ban-client set sshd banip <IP_ADDRESS>.
Knowledge graph12 entities Β· 11 connections

How they connect

An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.

Hover Β· drag to explore
12 entities
Chapters3 moments

Key Moments

Transcript28 segments

Full Transcript

Topics15 themes

What’s Discussed

Fail2banLinuxUbuntuDebianSSHBrute Force AttacksTerminal CommandsSystemctlAptJail.localMax RetryBan TimeFind TimeFail2ban-clientIP Address
Smart Objects12 Β· 11 links
ProductsΒ· 2
ConceptsΒ· 10