{"id":4291,"date":"2026-01-05T11:06:20","date_gmt":"2026-01-05T11:06:20","guid":{"rendered":"https:\/\/code2deploy.com\/blog\/?p=4291"},"modified":"2026-01-05T11:06:20","modified_gmt":"2026-01-05T11:06:20","slug":"protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications","status":"publish","type":"post","link":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/","title":{"rendered":"Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Brute-force attacks on SSH are a common threat to servers. In this guide, we\u2019ll set up <strong>Fail2ban<\/strong> on a bare-metal Linux server to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Automatically <strong>ban IPs<\/strong> after repeated failed login attempts<br><\/li>\n\n\n\n<li>Use <strong>UFW<\/strong> to block attackers at the firewall level<br><\/li>\n\n\n\n<li>Send <strong>real-time Slack alerts<\/strong> with custom server names<br><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This setup is <strong>free, secure, and production-ready<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1\ufe0f\u20e3 Install Fail2ban<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo apt update<br>sudo apt install fail2ban -y<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2\ufe0f\u20e3 Configure Global Settings and SSH Jail<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Edit the jail:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo vim \/etc\/fail2ban\/jail.local<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Paste this <strong>demo-friendly configuration<\/strong>:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>########################################<br># GLOBAL SETTINGS<br>########################################<br><br>[DEFAULT]<br># Whitelisted IPs (demo\/fake IPs)<br>ignoreip = 127.0.0.1\/8 ::1 203.0.113.10 203.0.113.11 203.0.113.12 198.51.100.5<br><br>bantime&nbsp; = 1h<br>findtime = 10m<br>maxretry = 3<br><br>########################################<br># SSH PROTECTION<br>########################################<br><br>[sshd]<br>enabled&nbsp; = true<br>port &nbsp; &nbsp; = 22<br>backend&nbsp; = systemd<br>logpath&nbsp; = %(sshd_log)s<br><br># Block attackers + Slack notifications<br>action = ufw<br>&nbsp; &nbsp; &nbsp; &nbsp; slack[servername=Demo-Server]<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Notes:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ignoreip \u2192 trusted IPs (demo only, replace with your own in real use)<br><\/li>\n\n\n\n<li>bantime \u2192 duration an attacker is banned<br><\/li>\n\n\n\n<li>maxretry \u2192 number of failed SSH attempts before banning<br><\/li>\n\n\n\n<li>action \u2192 ufw blocks attacker + Slack alerts<br><\/li>\n\n\n\n<li>servername \u2192 custom name shown in Slack<br><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3\ufe0f\u20e3 Configure Slack Notifications<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create the Slack action file:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo nano \/etc\/fail2ban\/action.d\/slack.conf<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Paste this:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>[Definition]<br>servername = Demo-Server<br><br>actionban = \/usr\/bin\/curl -s -X POST -H &#8216;Content-type: application\/json&#8217; \\<br>&nbsp; &#8211;data &#8216;{&#8220;text&#8221;:&#8221;\ud83d\udea8 <em>*Fail2Ban Alert*<\/em>\\n<em>*Server:*<\/em> &lt;<strong>servername<\/strong>&gt;\\n<em>*Jail:*<\/em> &lt;<strong>name<\/strong>&gt;\\n<em>*IP:*<\/em> &lt;<strong>ip<\/strong>&gt;\\n<em>*Attempts:*<\/em> &lt;<strong>failures<\/strong>&gt;\\n<em>*Time:*<\/em> &lt;<strong>time<\/strong>&gt;&#8221;}&#8217; \\<br>&nbsp; https:\/\/hooks.slack.com\/services\/<strong>**********<\/strong><em>*\/*<\/em><strong>*********\/*****************<\/strong><em>***<\/em>*<br><br>actionunban =<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Replace the webhook URL with your Slack <strong>Incoming Webhook<\/strong><strong><br><\/strong>\u2705 &lt;servername&gt; will now show Demo-Server in Slack alerts<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4\ufe0f\u20e3 Restart Fail2ban<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo systemctl restart fail2ban<br>sudo systemctl status fail2ban<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5\ufe0f\u20e3 Test Slack Alerts Safely<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Simulate a ban:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo fail2ban-client set sshd banip 1.2.3.4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83d\udd12 IP 1.2.3.4 is banned temporarily<br><\/li>\n\n\n\n<li>\ud83d\udea8 Slack alert arrives instantly<br><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Unban:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo fail2ban-client set sshd unbanip 1.2.3.4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>6\ufe0f\u20e3 Monitor Banned IPs<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Check jail status:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo fail2ban-client status sshd<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Check UFW rules:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo ufw status numbered<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Logs:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo tail -f \/var\/log\/fail2ban.log<br>sudo journalctl -u ssh -f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>7\ufe0f\u20e3 Unblock IPs<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Single IP:<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo fail2ban-client set sshd unbanip 203.0.113.20<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>All IPs:<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo fail2ban-client unban &#8211;all<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u26a0\ufe0f Don\u2019t manually remove UFW rules \u2014 always use Fail2ban to stay in sync.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>8\ufe0f\u20e3 Optional: Harden SSH (demo-friendly)<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Edit \/etc\/ssh\/sshd_config:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>PermitRootLogin no<br>PasswordAuthentication no<br>MaxAuthTries 3<br>LoginGraceTime 20<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Restart SSH:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>sudo systemctl restart ssh<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u2705 Demo Summary<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83d\udd12 Automatic detection of SSH brute-force attempts<br><\/li>\n\n\n\n<li>\ud83d\udeab UFW blocks unauthorized IPs<br><\/li>\n\n\n\n<li>\ud83d\udda5\ufe0f Slack alerts with <strong>custom server name<\/strong><strong><br><\/strong><\/li>\n\n\n\n<li>\u23f1\ufe0f Auto-unban after bantime<br><\/li>\n\n\n\n<li>\ud83d\udcaf Safe demo configuration using <strong>fake IPs<\/strong><strong><br><\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Brute-force attacks on SSH are a common threat to servers. In this guide, we\u2019ll set up Fail2ban on a bare-metal Linux server to: This setup is free, secure, and production-ready. 1\ufe0f\u20e3 Install Fail2ban sudo apt updatesudo apt install fail2ban -y 2\ufe0f\u20e3 Configure Global Settings and SSH Jail Edit the jail: sudo vim \/etc\/fail2ban\/jail.local Paste this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4293,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[242,899,898,897],"class_list":["post-4291","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cyber-security","tag-fail2ban","tag-server-os-layer-security","tag-ssh-brute-force-attacks","tag-ufw"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications - code2deploy.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications - code2deploy.com\" \/>\n<meta property=\"og:description\" content=\"Brute-force attacks on SSH are a common threat to servers. In this guide, we\u2019ll set up Fail2ban on a bare-metal Linux server to: This setup is free, secure, and production-ready. 1\ufe0f\u20e3 Install Fail2ban sudo apt updatesudo apt install fail2ban -y 2\ufe0f\u20e3 Configure Global Settings and SSH Jail Edit the jail: sudo vim \/etc\/fail2ban\/jail.local Paste this [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/\" \/>\n<meta property=\"og:site_name\" content=\"code2deploy.com\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-05T11:06:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code2deploy.com\/blog\/wp-content\/uploads\/2026\/01\/fail2ban-code2deploy.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"enam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"enam\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/\"},\"author\":{\"name\":\"enam\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#\\\/schema\\\/person\\\/e46930c19b999a87f12566fa8357481b\"},\"headline\":\"Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications\",\"datePublished\":\"2026-01-05T11:06:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/\"},\"wordCount\":420,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#\\\/schema\\\/person\\\/e46930c19b999a87f12566fa8357481b\"},\"image\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/01\\\/fail2ban-code2deploy.png\",\"keywords\":[\"fail2ban\",\"server os-layer security\",\"SSH Brute-Force Attacks\",\"UFW\"],\"articleSection\":[\"Security\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/\",\"url\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/\",\"name\":\"Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications - code2deploy.com\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/01\\\/fail2ban-code2deploy.png\",\"datePublished\":\"2026-01-05T11:06:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/#primaryimage\",\"url\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/01\\\/fail2ban-code2deploy.png\",\"contentUrl\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/01\\\/fail2ban-code2deploy.png\",\"width\":1536,\"height\":1024,\"caption\":\"fail2ban\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/\",\"name\":\"code2deploy.com\\\/blog\",\"description\":\"TechOps\",\"publisher\":{\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#\\\/schema\\\/person\\\/e46930c19b999a87f12566fa8357481b\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/#\\\/schema\\\/person\\\/e46930c19b999a87f12566fa8357481b\",\"name\":\"enam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g\",\"caption\":\"enam\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g\"},\"sameAs\":[\"https:\\\/\\\/code2deploy.com\\\/blog\"],\"url\":\"https:\\\/\\\/code2deploy.com\\\/blog\\\/author\\\/enam\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications - code2deploy.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/","og_locale":"en_US","og_type":"article","og_title":"Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications - code2deploy.com","og_description":"Brute-force attacks on SSH are a common threat to servers. In this guide, we\u2019ll set up Fail2ban on a bare-metal Linux server to: This setup is free, secure, and production-ready. 1\ufe0f\u20e3 Install Fail2ban sudo apt updatesudo apt install fail2ban -y 2\ufe0f\u20e3 Configure Global Settings and SSH Jail Edit the jail: sudo vim \/etc\/fail2ban\/jail.local Paste this [&hellip;]","og_url":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/","og_site_name":"code2deploy.com","article_published_time":"2026-01-05T11:06:20+00:00","og_image":[{"width":1536,"height":1024,"url":"https:\/\/code2deploy.com\/blog\/wp-content\/uploads\/2026\/01\/fail2ban-code2deploy.png","type":"image\/png"}],"author":"enam","twitter_card":"summary_large_image","twitter_misc":{"Written by":"enam","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/#article","isPartOf":{"@id":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/"},"author":{"name":"enam","@id":"https:\/\/code2deploy.com\/blog\/#\/schema\/person\/e46930c19b999a87f12566fa8357481b"},"headline":"Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications","datePublished":"2026-01-05T11:06:20+00:00","mainEntityOfPage":{"@id":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/"},"wordCount":420,"commentCount":0,"publisher":{"@id":"https:\/\/code2deploy.com\/blog\/#\/schema\/person\/e46930c19b999a87f12566fa8357481b"},"image":{"@id":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/#primaryimage"},"thumbnailUrl":"https:\/\/code2deploy.com\/blog\/wp-content\/uploads\/2026\/01\/fail2ban-code2deploy.png","keywords":["fail2ban","server os-layer security","SSH Brute-Force Attacks","UFW"],"articleSection":["Security"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/","url":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/","name":"Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications - code2deploy.com","isPartOf":{"@id":"https:\/\/code2deploy.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/#primaryimage"},"image":{"@id":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/#primaryimage"},"thumbnailUrl":"https:\/\/code2deploy.com\/blog\/wp-content\/uploads\/2026\/01\/fail2ban-code2deploy.png","datePublished":"2026-01-05T11:06:20+00:00","breadcrumb":{"@id":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/#primaryimage","url":"https:\/\/code2deploy.com\/blog\/wp-content\/uploads\/2026\/01\/fail2ban-code2deploy.png","contentUrl":"https:\/\/code2deploy.com\/blog\/wp-content\/uploads\/2026\/01\/fail2ban-code2deploy.png","width":1536,"height":1024,"caption":"fail2ban"},{"@type":"BreadcrumbList","@id":"https:\/\/code2deploy.com\/blog\/protect-your-server-from-ssh-brute-force-attacks-with-fail2ban-ufw-slack-notifications\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code2deploy.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Protect Your Server from SSH Brute-Force Attacks with Fail2Ban + UFW + Slack Notifications"}]},{"@type":"WebSite","@id":"https:\/\/code2deploy.com\/blog\/#website","url":"https:\/\/code2deploy.com\/blog\/","name":"code2deploy.com\/blog","description":"TechOps","publisher":{"@id":"https:\/\/code2deploy.com\/blog\/#\/schema\/person\/e46930c19b999a87f12566fa8357481b"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code2deploy.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/code2deploy.com\/blog\/#\/schema\/person\/e46930c19b999a87f12566fa8357481b","name":"enam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g","caption":"enam"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/d864e2f082f4499f8f1b33f004ec166eea77b9e94738553b120b6dca2410f203?s=96&d=mm&r=g"},"sameAs":["https:\/\/code2deploy.com\/blog"],"url":"https:\/\/code2deploy.com\/blog\/author\/enam\/"}]}},"_links":{"self":[{"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/posts\/4291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/comments?post=4291"}],"version-history":[{"count":1,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/posts\/4291\/revisions"}],"predecessor-version":[{"id":4294,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/posts\/4291\/revisions\/4294"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/media\/4293"}],"wp:attachment":[{"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/media?parent=4291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/categories?post=4291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code2deploy.com\/blog\/wp-json\/wp\/v2\/tags?post=4291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}