New

EmeraldHost 2.0 is here: faster, more intuitive, and made for everyone - the new panel!

Learn more
Guides
Basic ConfigurationInstall Fail2Ban

How to Install Fail2Ban on Your Linux VPS

Install Fail2Ban on a Linux VPS (Ubuntu/Debian)

1 min read
Oct 15, 2023

Fail2Ban protects your server from brute-force attacks by automatically banning IP addresses after multiple failed login attempts.

Install Fail2Ban

  1. Update system
    First, update the package lists:

    sudo apt update
    
  2. Install Fail2Ban
    Install Fail2Ban with the following command:

    sudo apt install fail2ban -y
    
  3. Enable service
    Make sure Fail2Ban starts automatically on boot:

    sudo systemctl enable fail2ban
    

Configure Fail2Ban

  1. Create configuration file
    Create a local configuration file so your settings are not overwritten during updates:

    sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
    
  2. Edit configuration
    Open the file:

    sudo nano /etc/fail2ban/jail.local
    
  3. Enable SSH protection
    Find the [sshd] section and adjust it:

    [sshd]
    enabled = true
    port = ssh
    maxretry = 5
    bantime = 3600
    findtime = 600
    
    Setting Description
    enabled Enables SSH protection
    port The SSH port (change this if you have modified your SSH port)
    maxretry Maximum failed attempts before an IP is banned
    bantime Ban duration in seconds (3600 = 1 hour)
    findtime Time window in seconds in which failed attempts are counted
  4. Restart Fail2Ban
    Save with Ctrl + O, close with Ctrl + X and restart Fail2Ban:

    sudo systemctl restart fail2ban
    

Check status

Check if Fail2Ban is running:

sudo systemctl status fail2ban

Show the status of SSH protection:

sudo fail2ban-client status sshd
Written byEmeraldHost Team
Last updated on Mar 16, 2026 Edit on GitHub

Did this article help you?

Your feedback helps us improve our guides.

Help shape the guides

€10.00 in credit for every new guide, €5.00 for every improvement.

Contact Support

Create a support ticket and our team will get back to you as soon as possible – personal and professional.

Go to Support
1257 members online

Discord Community

Connect with other players, get quick help from the community, and stay up to date with the latest news.

Join Discord

Join our Discord community 1257 members online right now