{"id":864,"date":"2009-12-02T03:10:25","date_gmt":"2009-12-02T08:10:25","guid":{"rendered":"http:\/\/g33kinfo.com\/info\/?p=864"},"modified":"2009-12-02T03:10:25","modified_gmt":"2009-12-02T08:10:25","slug":"linux-security-with-fail2ban","status":"publish","type":"post","link":"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/","title":{"rendered":"Linux Security with Fail2Ban"},"content":{"rendered":"<p>Linux is built to be inherently secure, and has a great track record of having superior security to its proprietary counterpart.<\/p>\n<p>However, in the world of server administration, paranoia is an asset. How else could someone get in? How can I prevent that? How can I be notified?<\/p>\n<p>One magnificent contribution to the security of Linux servers the world over is called fail2ban. Why should you care?<\/p>\n<p>From the Fail2ban main page:<\/p>\n<p>    Fail2ban scans log files like \/var\/log\/pwdfail or \/var\/log\/apache\/error_log and bans IP that makes too many password failures. It updates firewall rules to reject the IP address.<\/p>\n<p>So basically, it gives the finger to those mean people who are trying to brute-force your ssh server. And it blocks them at the packet level with iptables. No iptables knowledge necessary. (Though if you want a quickie, take a look at this short \u201cIptables for Linux\u201d intro).<\/p>\n<p>For openSUSE users, check to see if you have it available using zypper:<\/p>\n<p>[1049][root@laptop:~]$ zypper search fail2ban<\/p>\n<p>If you find it, use zypper install fail2ban to get it on your box.<\/p>\n<p>If you have trouble getting it installed, follow the seriously excellent advice on the fail2ban download page.<\/p>\n<p>When you get it installed, as root, edit your \/etc\/fail2ban\/jail.conf file.<\/p>\n<p>Put your ip addresses in the ignoreip list so you don\u2019t lock yourself out.<\/p>\n<p>bantime is in seconds. 1 hour is 1440 seconds. 24 hours is 86400. I put in at least 24 hours. Do what works for you.<\/p>\n<p>maxretry is how many tries a user gets before they\u2019re blocked for bantime seconds. 3 to 5 chances seems more than generous.<\/p>\n<p>Now to set up the notification.<\/p>\n<p>In the same file, look for the section called [ssh-iptables]. Change this section so it looks like this:<\/p>\n<p>[ssh-iptables]<\/p>\n<p>enabled  = true<br \/>\nfilter   = sshd<br \/>\naction   = iptables[name=SSH, port=ssh, protocol=tcp]<br \/>\n           sendmail-whois[name=SSH, dest=notrealemail@suseblog.com, sender=fail2ban@suseblog.com]<br \/>\nlogpath  = \/var\/log\/messages<br \/>\nmaxretry = 3<\/p>\n<p>If you don\u2019t want the \u2018whois\u2019 info, take out the \u2018-whois\u2019 from the sendmail part. Change the dest email to your own, and set the sender to whatever you want. Maxretry will override the default that you set further up. In logpath, put in the system log, or wherever your sshd logs stuff. Mine happens to be what you see there.<\/p>\n<p>When it\u2019s set up as you like, save and quit.<\/p>\n<p>Now, fire that bad fool up:<\/p>\n<p>[1607][root@mail:\/etc\/fail2ban]$ fail2ban-client start<br \/>\n2009-11-27 16:07:46,554 fail2ban.server : INFO   Starting Fail2ban v0.8.4<br \/>\n2009-11-27 16:07:46,555 fail2ban.server : INFO   Starting in daemon mode<br \/>\n[1607][root@mail:\/etc\/fail2ban]$<\/p>\n<p>To make it run when the machine restarts, use chkconfig:<\/p>\n<p>[1607][root@mail:\/etc\/fail2ban]$ chkconfig -a fail2ban<br \/>\nfail2ban                  0:off  1:off  2:off  3:on   4:off  5:on   6:off<br \/>\n[1610][root@mail:\/etc\/fail2ban]$ <\/p>\n<p>Within at least a few hours, you should get notifications. Or, you can have someone try and brute force your box and see if their IP gets banned.<\/p>\n<p>If you read through jail.conf, you\u2019ll see that fail2ban can do loads more than I\u2019ve covered here. But if you want a little more armor on ssh, your biggest target, slap fail2ban on your box.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux is built to be inherently secure, and has a great track record of having superior security to its proprietary counterpart. However, in the world of server administration, paranoia is an asset. How else could someone get in? How can I prevent that? How can I be notified? One magnificent contribution to the security of&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-864","post","type-post","status-publish","format-standard","hentry","category-info"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Linux Security with Fail2Ban - Linux Shtuff<\/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:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux Security with Fail2Ban - Linux Shtuff\" \/>\n<meta property=\"og:description\" content=\"Linux is built to be inherently secure, and has a great track record of having superior security to its proprietary counterpart. However, in the world of server administration, paranoia is an asset. How else could someone get in? How can I prevent that? How can I be notified? One magnificent contribution to the security of... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Shtuff\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:author\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:published_time\" content=\"2009-12-02T08:10:25+00:00\" \/>\n<meta name=\"author\" content=\"g33kadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/drsinger1111\" \/>\n<meta name=\"twitter:site\" content=\"@drsinger1111\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/linux-security-with-fail2ban\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/linux-security-with-fail2ban\\\/\"},\"author\":{\"name\":\"g33kadmin\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"headline\":\"Linux Security with Fail2Ban\",\"datePublished\":\"2009-12-02T08:10:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/linux-security-with-fail2ban\\\/\"},\"wordCount\":550,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"articleSection\":[\"General Info\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/linux-security-with-fail2ban\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/linux-security-with-fail2ban\\\/\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/linux-security-with-fail2ban\\\/\",\"name\":\"Linux Security with Fail2Ban - Linux Shtuff\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\"},\"datePublished\":\"2009-12-02T08:10:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/linux-security-with-fail2ban\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/linux-security-with-fail2ban\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/linux-security-with-fail2ban\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux Security with Fail2Ban\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\",\"name\":\"Linux Shtuff\",\"description\":\"Because I have CRS Syndrome...\",\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\",\"name\":\"g33kadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"contentUrl\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"width\":512,\"height\":512,\"caption\":\"g33kadmin\"},\"logo\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\"},\"description\":\"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\\\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....\",\"sameAs\":[\"https:\\\/\\\/thelinuxreport.com\",\"https:\\\/\\\/fb.me\\\/g33kinf0\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/drsinger1111\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linux Security with Fail2Ban - Linux Shtuff","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:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/","og_locale":"en_US","og_type":"article","og_title":"Linux Security with Fail2Ban - Linux Shtuff","og_description":"Linux is built to be inherently secure, and has a great track record of having superior security to its proprietary counterpart. However, in the world of server administration, paranoia is an asset. How else could someone get in? How can I prevent that? How can I be notified? One magnificent contribution to the security of... Read More","og_url":"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/","og_site_name":"Linux Shtuff","article_publisher":"https:\/\/fb.me\/g33kinf0","article_author":"https:\/\/fb.me\/g33kinf0","article_published_time":"2009-12-02T08:10:25+00:00","author":"g33kadmin","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/drsinger1111","twitter_site":"@drsinger1111","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/#article","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/"},"author":{"name":"g33kadmin","@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"headline":"Linux Security with Fail2Ban","datePublished":"2009-12-02T08:10:25+00:00","mainEntityOfPage":{"@id":"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/"},"wordCount":550,"commentCount":0,"publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"articleSection":["General Info"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/","url":"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/","name":"Linux Security with Fail2Ban - Linux Shtuff","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/#website"},"datePublished":"2009-12-02T08:10:25+00:00","breadcrumb":{"@id":"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/g33kinfo.com\/info\/linux-security-with-fail2ban\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/g33kinfo.com\/info\/"},{"@type":"ListItem","position":2,"name":"Linux Security with Fail2Ban"}]},{"@type":"WebSite","@id":"https:\/\/g33kinfo.com\/info\/#website","url":"https:\/\/g33kinfo.com\/info\/","name":"Linux Shtuff","description":"Because I have CRS Syndrome...","publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/g33kinfo.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547","name":"g33kadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","url":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","contentUrl":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","width":512,"height":512,"caption":"g33kadmin"},"logo":{"@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif"},"description":"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....","sameAs":["https:\/\/thelinuxreport.com","https:\/\/fb.me\/g33kinf0","https:\/\/x.com\/https:\/\/twitter.com\/drsinger1111"]}]}},"_links":{"self":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/comments?post=864"}],"version-history":[{"count":0,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/864\/revisions"}],"wp:attachment":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/media?parent=864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/categories?post=864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/tags?post=864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}