{"id":152,"date":"2005-09-05T12:57:00","date_gmt":"2005-09-05T12:57:00","guid":{"rendered":"http:\/\/adam.rosi-kessel.org\/weblog\/free_software\/code\/ssh_login_blocker.html"},"modified":"-0001-11-30T00:00:00","modified_gmt":"1970-01-01T05:00:00","slug":"ssh_login_blocker","status":"publish","type":"post","link":"https:\/\/adam.rosi-kessel.org\/weblog\/2005\/09\/05\/ssh_login_blocker","title":{"rendered":"ssh_login_blocker"},"content":{"rendered":"<p> Anyone who has a run a GNU\/Linux server on the Internet for more than a few weeks has probably noticed that they will occasionally get &#8220;hammered&#8221; by a robot attempting to make an ssh connection using common usernames and passwords. Usually these are not truly &#8220;brute force&#8221; attacks&#8212;they try 20-30 times, rather than thousands&#8212;but either way they are annoying. <\/p>\n<p> These attacks are rarely successful with a properly configured system, but they can use up bandwidth and system resources, and perhaps more troublesome is that they clog your log files so it is more difficult to detect a bona fide system attack. I suspect that at least some of these random ssh login attempts are accompanied by attacks on other known vulnerabilities, with the hope that the sysadmin won&#8217;t notice the more devious attack because the stupid attack is going on at the same time. <\/p>\n<p> Strangely, there is no &#8220;canonical&#8221; solution to guarding against these attacks. A few people have written up their own hack solutions, and here is mine. <\/p>\n<p> It&#8217;s called <a href=\"http:\/\/adam.rosi-kessel.org\/weblog\/free_software\/code\/ssh_login_blocker_code.html\">ssh_login_blocker<\/a>. It&#8217;s very simple&#8212;just drop it in \/etc\/init.d and make symlinks to the proper \/etc\/rc?.d directories (or just start it running from the command line). It must be run as root. You can configure it to allow a certain number of bad passwords or bad usernames before it blocks an IP address. You can also configure it to &#8220;reset&#8221; the bad username\/password count after a certain amount of time has passed. Just look at the first few lines of code and adjust the settings accordingly. <\/p>\n<p> If you are running it on a system to which you don&#8217;t have physical access, you should whitelist at least one IP address where you will be able to get in from in case something goes awry. <\/p>\n<ul>\n<li><a href=\"http:\/\/adam.rosi-kessel.org\/weblog\/free_software\/code\/ssh_login_blocker_code.html\">See the code<\/a><\/li>\n<li><a href=\"\/code\/ssh_login_blocker\">Download it here<\/a><\/li>\n<\/ul>\n<p> There are many improvements I&#8217;d like to make. For example, it should use libfile-tail-perl rather than running a shell for tail. It should have a &#8220;temporary blacklist&#8221; feature in addition to the current &#8220;permanent blacklist&#8221; feature. It should have an auto-whitelist function such that &#8220;known good&#8221; IP addresses get marked up. It should use something other than \/etc\/hosts.deny to block ip addresses&#8212;for example, iptables. It doesn&#8217;t do any of these things, but it works pretty well, and it makes me happy that my log files are not currently clogged with spurious login attempts. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Anyone who has a run a GNU\/Linux server on the Internet for more than a few weeks has probably noticed that they will occasionally get &#8220;hammered&#8221; by a robot attempting to make an ssh connection using common usernames and passwords. Usually these are not truly &#8220;brute force&#8221; attacks&#8212;they try 20-30 times, rather than thousands&#8212;but either [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/posts\/152"}],"collection":[{"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":0,"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"wp:attachment":[{"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adam.rosi-kessel.org\/weblog\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}