{"id":4624,"date":"2020-09-21T14:33:36","date_gmt":"2020-09-21T06:33:36","guid":{"rendered":"https:\/\/damogame.cn\/wordpress\/?p=4624"},"modified":"2020-09-21T15:05:08","modified_gmt":"2020-09-21T07:05:08","slug":"ssh%e8%ae%bf%e9%97%ae%e6%8e%a7%e5%88%b6%ef%bc%8c%e5%a4%9a%e6%ac%a1%e5%a4%b1%e8%b4%a5%e7%99%bb%e5%bd%95%e5%8d%b3%e5%b0%81%e6%8e%89ip%ef%bc%8c%e9%98%b2%e6%ad%a2%e6%9a%b4%e5%8a%9b%e7%a0%b4%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/4624","title":{"rendered":"ssh\u8bbf\u95ee\u63a7\u5236\uff0c\u591a\u6b21\u5931\u8d25\u767b\u5f55\u5373\u5c01\u6389IP\uff0c\u9632\u6b62\u66b4\u529b\u7834\u89e3"},"content":{"rendered":"<p><a href=\"https:\/\/www.cnblogs.com\/handongyu\/p\/6092625.html\">\u539f\u6587\u5730\u5740<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u4e00\u3001\u7cfb\u7edf\uff1aCentos6.3 64\u4f4d<\/p>\n<p>\u4e8c\u3001\u65b9\u6cd5\uff1a\u8bfb\u53d6\/var\/log\/secure\uff0c\u67e5\u627e\u5173\u952e\u5b57 Failed\uff0c\u4f8b\u5982\uff08\u6ce8\uff1a\u6587\u4e2d\u7684IP\u5730\u5740\u7279\u610f\u505a\u4e86\u5220\u51cf\uff09\uff1a<\/p>\n<p>Sep 17 09:08:09 localhost sshd[29087]: Failed password for root from\u00a013.7.3.6 port 44367 ssh2<br \/>\nSep 17 09:08:20\u00a0localhost sshd[29087]: Failed password for root from\u00a013.7.3.6 port 44367 ssh2<br \/>\nSep 17 09:10:02\u00a0localhost sshd[29223]: Failed password for root from\u00a013.7.3.6 port 56482 ssh2<br \/>\nSep 17 09:10:14\u00a0localhost sshd[29223]: Failed password for root from\u00a013.7.3.6 port 56482 ssh2<\/p>\n<p>\u4ece\u8fd9\u4e9b\u884c\u4e2d\u63d0\u53d6IP\u5730\u5740\uff0c\u5982\u679c\u6b21\u6570\u8fbe\u523010\u6b21(\u811a\u672c\u4e2d\u5224\u65ad\u6b21\u6570\u5b57\u7b26\u957f\u5ea6\u662f\u5426\u5927\u4e8e1)\u5219\u5c06\u8be5IP\u5199\u5230 \/etc\/hosts.deny\u4e2d\u3002<\/p>\n<p>\u4e09\u3001\u6b65\u9aa4\uff1a<\/p>\n<p>1\u3001\u5148\u628a\u59cb\u7ec8\u5141\u8bb8\u7684IP\u586b\u5165 \/etc\/hosts.allow \uff0c\u8fd9\u5f88\u91cd\u8981\uff01\u6bd4\u5982\uff1a<br \/>\nsshd:19.16.18.1:allow<br \/>\nsshd:19.16.18.2:allow<\/p>\n<p>2\u3001\u811a\u672c \/usr\/local\/bin\/secure_ssh.sh<\/p>\n<div class=\"cnblogs_code\">\n<pre>#! \/bin\/bash\r\ncat \/var\/log\/secure|awk '\/Failed\/{print $(NF-3)}'|sort|uniq -c|awk '{print $2\"=\"$1;}' &gt; \/usr\/local\/bin\/black.list\r\nfor i in `cat  \/usr\/local\/bin\/black.list`\r\ndo\r\n  IP=`echo $i |awk -F= '{print $1}'`\r\n  NUM=`echo $i|awk -F= '{print $2}'`\r\n  if [ ${#NUM} -gt 1 ]; then\r\n    grep $IP \/etc\/hosts.deny &gt; \/dev\/null\r\n    if [ $? -gt 0 ];then\r\n      echo \"sshd:$IP:deny\" &gt;&gt; \/etc\/hosts.deny\r\n    fi\r\n  fi\r\ndone<\/pre>\n<\/div>\n<p>3\u3001\u5c06secure_ssh.sh\u811a\u672c\u653e\u5165cron\u8ba1\u5212\u4efb\u52a1\uff0c\u6bcf1\u5206\u949f\u6267\u884c\u4e00\u6b21\u3002<br \/>\n# crontab -e<br \/>\n*\/1 * * * *\u00a0 sh \/usr\/local\/bin\/secure_ssh.sh<\/p>\n<p>\u56db\u3001\u6d4b\u8bd5\uff1a<\/p>\n<p>1\u3001\u5f00\u4e24\u4e2a\u7ec8\u7aef\u7a97\u53e3\uff0c\u4e00\u4e2assh\u8fde\u4e0a\u670d\u52a1\u5668\uff0c\u53e6\u4e00\u4e2a\u7528\u9519\u8bef\u7684\u5bc6\u7801\u8fde\u63a5\u670d\u52a1\u5668\u51e0\u6b21\u3002<\/p>\n<p>\u5f88\u5feb\uff0c\u670d\u52a1\u5668\u4e0a\u9ed1\u540d\u5355\u6587\u4ef6\u91cc\u5df2\u7ecf\u6709\u8bb0\u5f55\u4e86\uff1a<br \/>\n[root@ ~]# $ cat \/usr\/local\/bin\/black.txt<br \/>\n13.26.21.27=3<\/p>\n<p>\u518d\u770b\u770b\u670d\u52a1\u5668\u4e0a\u7684hosts.deny<br \/>\n[root@ ~]# cat \/etc\/hosts.deny<br \/>\nsshd:13.7.3.6:deny<br \/>\nsshd:92.4.0.4:deny<br \/>\nsshd:94.10.4.2:deny<br \/>\nsshd:94.4.1.6:deny<br \/>\nsshd:11.64.11.5:deny<\/p>\n<p>2\u3001\u4ece\u53e6\u4e00\u4e2a\u7ec8\u7aef\u7a97\u53e3\u7ee7\u7eed\u201c\u66b4\u529b\u201d\u8fde\u63a5\u670d\u52a1\u5668\u3002<\/p>\n<p>\u770b\u770b\u670d\u52a1\u5668\u4e0a\u7684\u9ed1\u540d\u5355\u6587\u4ef6\uff1a<br \/>\n[root@ ~]# cat \/usr\/local\/bin\/black.txt<br \/>\n13.26.21.27=6<\/p>\n<p>\u518d\u770b\u770b\u670d\u52a1\u5668\u4e0a\u7684hosts.deny<br \/>\n[root@ ~]# cat \/etc\/hosts.deny<br \/>\nsshd:13.7.3.6:deny<br \/>\nsshd:92.4.0.4:deny<br \/>\nsshd:94.10.4.2:deny<br \/>\nsshd:94.4.1.6:deny<br \/>\nsshd:11.64.11.5:deny<br \/>\nsshd:13.26.21.27:deny<\/p>\n<p>IP \u5df2\u7ecf\u88ab\u52a0\u5165\u5230\u670d\u52a1\u5668\u7684hosts.deny\uff0c\u518d\u7528\u6b63\u786e\u7684\u5bc6\u7801\u8fde\u63a5\u670d\u52a1\u5668\uff0c\u88ab\u62d2\u7edd\uff1a<br \/>\n$ ssh root@myserver.mydomain.com -p 2333<br \/>\nssh_exchange_identification: Connection closed by remote host<\/p>\n<p>\u6ce8\uff1a<br \/>\n1.\u811a\u672c\u4e3a\u540c\u4e8b\u7f16\u5199\u3002<\/p>\n<p>2.\u670d\u52a1\u5668sshd\u7aef\u53e3\u5df2\u6539\u4e3a2333\uff0c\u4e8b\u5b9e\u8bc1\u660e\uff0c\u6539\u4e86\u7aef\u53e3\u540e\uff0c\u66b4\u529b\u7834\u89e3\u7684ssh\u8fde\u63a5\u6570\u9510\u51cf\uff0c\u5475\u5475\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740 &nbsp; \u4e00\u3001\u7cfb\u7edf\uff1aCen<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[125],"class_list":["post-4624","post","type-post","status-publish","format-standard","hentry","tag-09-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/4624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=4624"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/4624\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=4624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=4624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=4624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}