{"id":245,"date":"2008-09-10T10:12:21","date_gmt":"2008-09-10T18:12:21","guid":{"rendered":"http:\/\/www.khaitan.org\/blog\/?p=245"},"modified":"2008-09-10T10:12:21","modified_gmt":"2008-09-10T18:12:21","slug":"prevent-ssh-password-attacks-using-denyhosts-package","status":"publish","type":"post","link":"https:\/\/www.khaitan.org\/blog\/2008\/09\/prevent-ssh-password-attacks-using-denyhosts-package\/","title":{"rendered":"Prevent SSH password attacks using denyhosts package"},"content":{"rendered":"<p><a href=\"http:\/\/www.khaitan.org\/blog\/wp-content\/uploads\/2008\/09\/illegal_users.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-246\" title=\"illegal_users\" src=\"http:\/\/www.khaitan.org\/blog\/wp-content\/uploads\/2008\/09\/illegal_users.png\" alt=\"\" width=\"328\" height=\"433\" \/><\/a><\/p>\n<p>When I saw this in my daily log report. I was like WTF! Script kiddies are having fun. Little bit of Googling and I installed the denyhosts package on Feodra Core 7. Here&#8217;s the step by step guide.<\/p>\n<p><code>shell>yum install denyhosts<br \/>\nshell>\/etc\/init.d\/denyhosts start<\/code><\/p>\n<p>Most probably denyhosts is going to run on server restarts. However, make sure that&#8217;s the case by<\/p>\n<p><code>shell>chkconfig denyhosts on<\/code><\/p>\n<p>The denyhosts package watches the \/var\/log\/secure log file at a fixed interval and then when it finds a match (like illegal login attempts, etc.) it adds an entry in the <a href=\"http:\/\/linux.die.net\/man\/5\/hosts.deny\">\/etc\/hosts.deny<\/a> file. The \/etc\/hosts.deny file contains pairs of entries in network daemon, client ip (or hostname) format which looks like this:<\/p>\n<p><code>daemon_name: X.Y.Z.W<\/code><br \/>\n\u00a0<br \/>\nAfter installing the denyhosts package, you can tweak the configuration by modifying the \/etc\/denyhosts.conf file. Here&#8217;s what I changed essentially<\/p>\n<p><code><br \/>\n#Block the host after 3 failed attempts<br \/>\n#for non-existing logins<br \/>\nDENY_THRESHOLD_INVALID = 3<br \/>\n#Block the host after 5 failed<br \/>\n#attempts of existing logins<br \/>\nDENY_THRESHOLD_VALID = 5<br \/>\n#Block after 3 failed attempts for root login.<br \/>\n#Ideally, you should disable root login for ssh<br \/>\nDENY_THRESHOLD_ROOT = 3<br \/>\n#Good idea to capture the host name from IP<br \/>\nHOSTNAME_LOOKUP=YES<br \/>\n#I left this blank as we capture the<br \/>\n#reports via logwatch<br \/>\nADMIN_EMAIL =<br \/>\n<\/code><\/p>\n<p>Here&#8217;s what my \/etc\/hosts.deny looked like after a few days<\/p>\n<p><code># DenyHosts: Sun Sep  7 06:00:08 2008 | sshd: 210.51.1.231<br \/>\nsshd: 210.51.1.231<br \/>\n# DenyHosts: Sun Sep  7 18:34:01 2008 | sshd: 117.36.50.66<br \/>\nsshd: 117.36.50.66<br \/>\n# DenyHosts: Mon Sep  8 05:05:04 2008 | sshd: 218.4.150.50<br \/>\nsshd: 218.4.150.50<br \/>\n# DenyHosts: Tue Sep  9 01:36:18 2008 | sshd: 12.174.168.124<br \/>\nsshd: 12.174.168.124<\/code><\/p>\n<p>Don&#8217;t forget to restart denyhosts if you change the config file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I saw this in my daily log report. I was like WTF! Script kiddies are having fun. Little bit of Googling and I installed the denyhosts package on Feodra Core 7. Here&#8217;s the step by step guide. shell>yum install denyhosts shell>\/etc\/init.d\/denyhosts start Most probably denyhosts is going to run on server restarts. However, make [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[98],"tags":[],"_links":{"self":[{"href":"https:\/\/www.khaitan.org\/blog\/wp-json\/wp\/v2\/posts\/245"}],"collection":[{"href":"https:\/\/www.khaitan.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.khaitan.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.khaitan.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.khaitan.org\/blog\/wp-json\/wp\/v2\/comments?post=245"}],"version-history":[{"count":0,"href":"https:\/\/www.khaitan.org\/blog\/wp-json\/wp\/v2\/posts\/245\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.khaitan.org\/blog\/wp-json\/wp\/v2\/media?parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.khaitan.org\/blog\/wp-json\/wp\/v2\/categories?post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.khaitan.org\/blog\/wp-json\/wp\/v2\/tags?post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}