{"id":158,"date":"2015-10-06T16:43:23","date_gmt":"2015-10-06T15:43:23","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=158"},"modified":"2015-10-06T16:43:23","modified_gmt":"2015-10-06T15:43:23","slug":"configuring-fail2ban-on-linux-servers-blockdrop-ip-addresses-that-get-ssh-or-imap-password-wrong-more-than-3-times","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2015\/10\/06\/configuring-fail2ban-on-linux-servers-blockdrop-ip-addresses-that-get-ssh-or-imap-password-wrong-more-than-3-times\/","title":{"rendered":"Configuring Fail2Ban on Linux Servers (BLOCK\/DROP IP addresses that get SSH or IMAP password wrong more than 3 times)"},"content":{"rendered":"<p>So, I was figuring, because of all the brute force attacks on my servers that I would bother to install fail2ban. Something even better than this would be to change the port your SSH runs on..<\/p>\n<p>Step 1. Install Fail2ban<br \/>\nUbuntu and Debian Systems<\/p>\n<pre>\r\napt-get install fail2ban\r\n<\/pre>\n<p>Redhat, Fedora and CentOS based Systems<\/p>\n<pre>\r\nyum install fail2ban\r\n<\/pre>\n<p>Step 2. Copy the reference config file and edit it in Vi (or nano)<\/p>\n<pre>\r\ncp \/etc\/fail2ban\/jail.conf \/etc\/fail2ban\/jail.local\r\nvi \/etc\/fail2ban\/jail.local\r\n<\/pre>\n<p>Step 3. Configure bantime (default 600seconds), and the max_retry (3 attempts).<br \/>\n<italic> If someone tries to connect 3 times or more with the wrong password, they&#8217;ll be added to IPTABLES DROP rule for 600 seconds <\/italic><\/p>\n<pre>\r\n# \"bantime\" is the number of seconds that a host is banned.\r\nbantime  = 600\r\n\r\nmaxretry = 3\r\n\r\n<\/pre>\n<p>By default fail2ban starts banning people on SSH immediately, but I found it was also possible to configure fail2ban to block ip addresses attempting to brute force hack my email accounts, here is how I did it.<\/p>\n<pre>\r\n[sasl]\r\n\r\nenabled  = false\r\nport     = smtp,ssmtp,submission,imap2,imap3,imaps,pop3,pop3s\r\nfilter   = postfix-sasl\r\n# You might consider monitoring \/var\/log\/mail.warn instead if you are\r\n# running postfix since it would provide the same log lines at the\r\n# \"warn\" level but overall at the smaller filesize.\r\nlogpath  = \/var\/log\/mail.log\r\n\r\n<\/pre>\n<p>It&#8217;s possible to alter this configuration but for most people the logpath for SSH is auth.log<\/p>\n<pre>\r\n[ssh]\r\n\r\nenabled  = true\r\nport     = ssh\r\nfilter   = sshd\r\nlogpath  = \/var\/log\/auth.log\r\nmaxretry = 6\r\n\r\n<\/pre>\n<p>Step 4: Restart the Fail2ban service<\/p>\n<pre>\r\n# most init.d based systems\r\n\/etc\/init.d\/fail2ban restart\r\n# some systemD systems\r\nservice fail2ban restart\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So, I was figuring, because of all the brute force attacks on my servers that I would bother to install fail2ban. Something even better than this would be to change the port your SSH runs on.. Step 1. Install Fail2ban &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2015\/10\/06\/configuring-fail2ban-on-linux-servers-blockdrop-ip-addresses-that-get-ssh-or-imap-password-wrong-more-than-3-times\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":1,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/158\/revisions\/159"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}