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 fail2banand confirm with 'y'. - β
After installation, verify the service status with
sudo systemctl status fail2ban. If inactive, enable it usingsudo 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, andfilter = sshd. - π The
logpathspecifies the log file to monitor, typically/var/log/auth.log. - π
maxretrysets the maximum failed attempts before an IP is banned (e.g., 5). - β³
bantimedefines the duration of the ban in seconds (e.g., 600 seconds for 1 hour). - β±οΈ
findtimeis 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 statusto view active jails, such assshd. - π 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