انتقل إلى المحتوى

الدروس الأمان متوسط1 دقائق قراءة

How to Protect SSH with Fail2ban

Install and configure Fail2ban on Ubuntu to automatically ban IP addresses that repeatedly fail SSH logins, and learn how to unban yourself.

بواسطة فريق تحرير ZSOLNET آخر تحديث

هذه الصفحة غير متاحة بالعربية بعد، لذا تُعرض بالإنجليزية.

أهم النقاط

  • Fail2ban watches logs and bans IPs after repeated failures.
  • Configure it in jail.local, never jail.conf.
  • Add your own IP to ignoreip so you can't lock yourself out.

Install

sudo apt install fail2ban

Configure

Create /etc/fail2ban/jail.local:

[DEFAULT]
bantime  = 1h
findtime = 10m
maxretry = 5
ignoreip = 127.0.0.1/8 ::1 198.51.100.7   # add your own IP

[sshd]
enabled = true
backend = systemd

Restart and check:

sudo systemctl restart fail2ban
sudo fail2ban-client status sshd

Useful commands

sudo fail2ban-client status                       # list jails
sudo fail2ban-client set sshd unbanip 198.51.100.7
sudo tail -f /var/log/fail2ban.log

Fail2ban has ready-made jails for Nginx, Apache and mail servers too — enable them the same way in jail.local.

الأسئلة الشائعة

Do I still need Fail2ban if I use SSH keys?

Keys stop the attacks from succeeding; Fail2ban reduces the noise and load from them. Both together are a good default.

How do I unban an IP?

Run sudo fail2ban-client set sshd unbanip 198.51.100.7.

شارك X LinkedIn Facebook

الدخول إلى حسابك

أدِر نطاقاتك واستضافتك وفواتيرك من مكان واحد.

اتصال آمن مباشرة مع منطقة العملاء في ZSOLNET.

ليس لديك حساب؟