{"id":504586,"date":"2025-04-10T15:28:44","date_gmt":"2025-04-10T13:28:44","guid":{"rendered":"https:\/\/hexabyte.se\/?post_type=kb&#038;p=504586"},"modified":"2025-04-10T15:28:45","modified_gmt":"2025-04-10T13:28:45","slug":"fail2ban","status":"publish","type":"kb","link":"https:\/\/hexabyte.se\/en\/kb\/fail2ban\/","title":{"rendered":"Protect your VPS with Fail2Ban"},"content":{"rendered":"\n<p><strong>Fail2Ban<\/strong>\u00a0\u00e4r ett s\u00e4kerhetsverktyg som skyddar din server mot brute force-attacker, s\u00e4rskilt via SSH. Det \u00f6vervakar loggar och blockerar automatiskt IP-adresser som g\u00f6r upprepade felaktiga inloggningsf\u00f6rs\u00f6k. Det minskar risken f\u00f6r intr\u00e5ng markant och \u00e4r ett m\u00e5ste p\u00e5 en VPS med publik IP.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Varf\u00f6r anv\u00e4nda Fail2Ban?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Skyddar mot brute force-attacker p\u00e5 SSH, FTP, mailservrar m.m.<\/li>\n\n\n\n<li>Blockerar angripande IP-adresser automatiskt via brandv\u00e4ggen (iptables\/nftables).<\/li>\n\n\n\n<li>Kr\u00e4ver minimalt med resurser.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Installera och konfigurera Fail2Ban p\u00e5 Ubuntu 24.04<\/h3>\n\n\n\n<div class=\"schema-how-to wp-block-yoast-how-to-block\"><p class=\"schema-how-to-total-time\"><span class=\"schema-how-to-duration-time-text\">Time needed:&nbsp;<\/span>15 minutes<\/p><p class=\"schema-how-to-description\">Steg-f\u00f6r-steg: Installera Fail2Ban p\u00e5 Ubuntu 24.04<\/p> <ol class=\"schema-how-to-steps\"><li class=\"schema-how-to-step\" id=\"how-to-step-1744291436428\"><strong class=\"schema-how-to-step-name\"><strong>Installera Fail2Ban<\/strong><\/strong> <p class=\"schema-how-to-step-text\"><code>sudo apt install fail2ban -y<\/code><\/p> <\/li><li class=\"schema-how-to-step\" id=\"how-to-step-1744291468720\"><strong class=\"schema-how-to-step-name\"><strong>Kopiera standardkonfigurationen<\/strong><\/strong> <p class=\"schema-how-to-step-text\">Skapa en lokal konfigurationsfil som inte skrivs \u00f6ver vid uppdateringar:<br\/><code>sudo cp \/etc\/fail2ban\/jail.conf \/etc\/fail2ban\/jail.local<\/code><\/p> <\/li><li class=\"schema-how-to-step\" id=\"how-to-step-1744291494498\"><strong class=\"schema-how-to-step-name\"><strong>Aktivera skydd f\u00f6r SSH<\/strong><\/strong> <p class=\"schema-how-to-step-text\">\u00d6ppna konfigurationsfilen:<br\/><code>sudo nano \/etc\/fail2ban\/jail.local<\/code><br\/>L\u00e4gg till eller kontrollera att f\u00f6ljande finns:<br\/><code>[sshd]<\/code><br\/><code>enabled = true<\/code><br\/><code>port = ssh<\/code><br\/><code>logpath = %(sshd_log)s<\/code><br\/><code>maxretry = 5<\/code><\/p> <\/li><li class=\"schema-how-to-step\" id=\"how-to-step-1744291538673\"><strong class=\"schema-how-to-step-name\"><strong>Starta och aktivera Fail2Ban<\/strong><\/strong> <p class=\"schema-how-to-step-text\"><code>sudo systemctl enable --now fail2ban<\/code><\/p> <\/li><li class=\"schema-how-to-step\" id=\"how-to-step-1744291556966\"><strong class=\"schema-how-to-step-name\"><strong>Verifiera att det fungerar<\/strong><\/strong> <p class=\"schema-how-to-step-text\"><code>sudo fail2ban-client status sshd<\/code><br\/>Du b\u00f6r se &#8221;Status for the jail: sshd&#8221; och antal bans (0 om ingen misslyckat f\u00f6rs\u00f6k \u00e4n).<\/p> <\/li><\/ol><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Tips<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Loggfil:<\/strong>\u00a0<code>\/var\/log\/fail2ban.log<\/code>\u00a0visar vad Fail2Ban g\u00f6r.<\/li>\n\n\n\n<li><strong>Brandv\u00e4gg:<\/strong>\u00a0Se till att du inte blockerar dig sj\u00e4lv. Whitelist din egna IP i\u00a0<code>\/etc\/fail2ban\/jail.local<\/code> om du kommer fr\u00e5n en fast IP-adress.<\/li>\n\n\n\n<li><strong>Ut\u00f6kat skydd:<\/strong>\u00a0Fail2Ban kan \u00e4ven skydda t.ex. Nginx, Apache, Postfix \u2013 men SSH \u00e4r viktigast att b\u00f6rja med.<\/li>\n<\/ul>\n","protected":false},"parent":0,"menu_order":0,"template":"","class_list":["post-504586","kb","type-kb","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Skydda din VPS med Fail2Ban<\/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:\/\/hexabyte.se\/en\/kb\/fail2ban\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Skydda din VPS med Fail2Ban\" \/>\n<meta property=\"og:description\" content=\"Fail2Ban\u00a0\u00e4r ett s\u00e4kerhetsverktyg som skyddar din server mot brute force-attacker, s\u00e4rskilt via SSH. Det \u00f6vervakar loggar och blockerar automatiskt IP-adresser som g\u00f6r upprepade felaktiga inloggningsf\u00f6rs\u00f6k. Det minskar risken f\u00f6r intr\u00e5ng markant och \u00e4r ett m\u00e5ste p\u00e5 en VPS med publik IP. Varf\u00f6r anv\u00e4nda Fail2Ban? Installera och konfigurera Fail2Ban p\u00e5 Ubuntu 24.04 Tips\" \/>\n<meta property=\"og:url\" content=\"https:\/\/hexabyte.se\/en\/kb\/fail2ban\/\" \/>\n<meta property=\"og:site_name\" content=\"Hexabyte\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-10T13:28:45+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/\",\"url\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/\",\"name\":\"Skydda din VPS med Fail2Ban\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hexabyte.se\\\/#website\"},\"datePublished\":\"2025-04-10T13:28:44+00:00\",\"dateModified\":\"2025-04-10T13:28:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Hem\",\"item\":\"https:\\\/\\\/hexabyte.se\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Kunskapsbank\",\"item\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Skydda din VPS med Fail2Ban\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/hexabyte.se\\\/#website\",\"url\":\"https:\\\/\\\/hexabyte.se\\\/\",\"name\":\"Hexabyte\",\"description\":\"Serverl\u00f6sningar\",\"publisher\":{\"@id\":\"https:\\\/\\\/hexabyte.se\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/hexabyte.se\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/hexabyte.se\\\/#organization\",\"name\":\"Hexabyte AB\",\"url\":\"https:\\\/\\\/hexabyte.se\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/hexabyte.se\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/hexabyte.se\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/hexabyte-clear.svg\",\"contentUrl\":\"https:\\\/\\\/hexabyte.se\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/hexabyte-clear.svg\",\"width\":318,\"height\":57,\"caption\":\"Hexabyte AB\"},\"image\":{\"@id\":\"https:\\\/\\\/hexabyte.se\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"HowTo\",\"@id\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/#howto-1\",\"name\":\"Skydda din VPS med Fail2Ban\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/\"},\"description\":\"Steg-f\u00f6r-steg: Installera Fail2Ban p\u00e5 Ubuntu 24.04\",\"totalTime\":\"P0DT0H15M\",\"step\":[{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/#how-to-step-1744291436428\",\"name\":\"Installera Fail2Ban\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"sudo apt install fail2ban -y\"}]},{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/#how-to-step-1744291468720\",\"name\":\"Kopiera standardkonfigurationen\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"Skapa en lokal konfigurationsfil som inte skrivs \u00f6ver vid uppdateringar:sudo cp \\\/etc\\\/fail2ban\\\/jail.conf \\\/etc\\\/fail2ban\\\/jail.local\"}]},{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/#how-to-step-1744291494498\",\"name\":\"Aktivera skydd f\u00f6r SSH\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"\u00d6ppna konfigurationsfilen:sudo nano \\\/etc\\\/fail2ban\\\/jail.localL\u00e4gg till eller kontrollera att f\u00f6ljande finns:[sshd]enabled = trueport = sshlogpath = %(sshd_log)smaxretry = 5\"}]},{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/#how-to-step-1744291538673\",\"name\":\"Starta och aktivera Fail2Ban\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"sudo systemctl enable --now fail2ban\"}]},{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/hexabyte.se\\\/kb\\\/fail2ban\\\/#how-to-step-1744291556966\",\"name\":\"Verifiera att det fungerar\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"sudo fail2ban-client status sshdDu b\u00f6r se \\\"Status for the jail: sshd\\\" och antal bans (0 om ingen misslyckat f\u00f6rs\u00f6k \u00e4n).\"}]}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Protect your VPS with Fail2Ban","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:\/\/hexabyte.se\/en\/kb\/fail2ban\/","og_locale":"en_US","og_type":"article","og_title":"Skydda din VPS med Fail2Ban","og_description":"Fail2Ban\u00a0\u00e4r ett s\u00e4kerhetsverktyg som skyddar din server mot brute force-attacker, s\u00e4rskilt via SSH. Det \u00f6vervakar loggar och blockerar automatiskt IP-adresser som g\u00f6r upprepade felaktiga inloggningsf\u00f6rs\u00f6k. Det minskar risken f\u00f6r intr\u00e5ng markant och \u00e4r ett m\u00e5ste p\u00e5 en VPS med publik IP. Varf\u00f6r anv\u00e4nda Fail2Ban? Installera och konfigurera Fail2Ban p\u00e5 Ubuntu 24.04 Tips","og_url":"https:\/\/hexabyte.se\/en\/kb\/fail2ban\/","og_site_name":"Hexabyte","article_modified_time":"2025-04-10T13:28:45+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/hexabyte.se\/kb\/fail2ban\/","url":"https:\/\/hexabyte.se\/kb\/fail2ban\/","name":"Protect your VPS with Fail2Ban","isPartOf":{"@id":"https:\/\/hexabyte.se\/#website"},"datePublished":"2025-04-10T13:28:44+00:00","dateModified":"2025-04-10T13:28:45+00:00","breadcrumb":{"@id":"https:\/\/hexabyte.se\/kb\/fail2ban\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/hexabyte.se\/kb\/fail2ban\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/hexabyte.se\/kb\/fail2ban\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Hem","item":"https:\/\/hexabyte.se\/"},{"@type":"ListItem","position":2,"name":"Kunskapsbank","item":"https:\/\/hexabyte.se\/kb\/"},{"@type":"ListItem","position":3,"name":"Skydda din VPS med Fail2Ban"}]},{"@type":"WebSite","@id":"https:\/\/hexabyte.se\/#website","url":"https:\/\/hexabyte.se\/","name":"Hexabytes","description":"Server solutions","publisher":{"@id":"https:\/\/hexabyte.se\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/hexabyte.se\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/hexabyte.se\/#organization","name":"Hexabyte AB","url":"https:\/\/hexabyte.se\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hexabyte.se\/#\/schema\/logo\/image\/","url":"https:\/\/hexabyte.se\/wp-content\/uploads\/2023\/12\/hexabyte-clear.svg","contentUrl":"https:\/\/hexabyte.se\/wp-content\/uploads\/2023\/12\/hexabyte-clear.svg","width":318,"height":57,"caption":"Hexabyte AB"},"image":{"@id":"https:\/\/hexabyte.se\/#\/schema\/logo\/image\/"}},{"@type":"HowTo","@id":"https:\/\/hexabyte.se\/kb\/fail2ban\/#howto-1","name":"Protect your VPS with Fail2Ban","mainEntityOfPage":{"@id":"https:\/\/hexabyte.se\/kb\/fail2ban\/"},"description":"Step-by-Step: Install Fail2Ban on Ubuntu 24.04","totalTime":"P0DT0H15M","step":[{"@type":"HowToStep","url":"https:\/\/hexabyte.se\/kb\/fail2ban\/#how-to-step-1744291436428","name":"Installera Fail2Ban","itemListElement":[{"@type":"HowToDirection","text":"sudo apt install fail2ban -y"}]},{"@type":"HowToStep","url":"https:\/\/hexabyte.se\/kb\/fail2ban\/#how-to-step-1744291468720","name":"Kopiera standardkonfigurationen","itemListElement":[{"@type":"HowToDirection","text":"Skapa en lokal konfigurationsfil som inte skrivs \u00f6ver vid uppdateringar:sudo cp \/etc\/fail2ban\/jail.conf \/etc\/fail2ban\/jail.local"}]},{"@type":"HowToStep","url":"https:\/\/hexabyte.se\/kb\/fail2ban\/#how-to-step-1744291494498","name":"Aktivera skydd f\u00f6r SSH","itemListElement":[{"@type":"HowToDirection","text":"\u00d6ppna konfigurationsfilen:sudo nano \/etc\/fail2ban\/jail.localL\u00e4gg till eller kontrollera att f\u00f6ljande finns:[sshd]enabled = trueport = sshlogpath = %(sshd_log)smaxretry = 5"}]},{"@type":"HowToStep","url":"https:\/\/hexabyte.se\/kb\/fail2ban\/#how-to-step-1744291538673","name":"Starta och aktivera Fail2Ban","itemListElement":[{"@type":"HowToDirection","text":"sudo systemctl enable --now fail2ban"}]},{"@type":"HowToStep","url":"https:\/\/hexabyte.se\/kb\/fail2ban\/#how-to-step-1744291556966","name":"Verifiera att det fungerar","itemListElement":[{"@type":"HowToDirection","text":"sudo fail2ban-client status sshdDu b\u00f6r se \"Status for the jail: sshd\" och antal bans (0 om ingen misslyckat f\u00f6rs\u00f6k \u00e4n)."}]}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/hexabyte.se\/en\/wp-json\/wp\/v2\/kb\/504586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hexabyte.se\/en\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/hexabyte.se\/en\/wp-json\/wp\/v2\/types\/kb"}],"wp:attachment":[{"href":"https:\/\/hexabyte.se\/en\/wp-json\/wp\/v2\/media?parent=504586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}