{"id":25,"date":"2015-05-10T18:02:30","date_gmt":"2015-05-10T10:02:30","guid":{"rendered":"http:\/\/yyshell.com\/?p=25"},"modified":"2015-09-14T10:11:51","modified_gmt":"2015-09-14T02:11:51","slug":"%e5%a6%82%e4%bd%95%e6%9b%b4%e6%94%b9centos7%e7%9a%84ssh%e7%ab%af%e5%8f%a3","status":"publish","type":"post","link":"https:\/\/yyshell.com\/?p=25","title":{"rendered":"\u5982\u4f55\u66f4\u6539CentOS7\u7684SSH\u7aef\u53e3"},"content":{"rendered":"<p>\u6211\u4eec\u7684linux\u670d\u52a1\u5668\u7ecf\u5e38\u767b\u5f55\u540e\u4f1a\u53d7\u5230\u8fd9\u6837\u7684\u63d0\u793a\uff1a<\/p>\n<pre class=\"lang:default decode:true \">Last failed login: Fri Aug 22 19:31:42 CEST 2014 from xx.xxx.xxx.xx on ssh:notty\r\nThere were 17307 failed login attempts since the last successful login.\r\nLast login: Wed Aug 13 11:11:55 2014 from yyy-yyy-yyy-yyy<\/pre>\n<p>\u5bf9\u4e8e\u6b64\u7c7b\u66b4\u529b\u7834\u89e3\u5bc6\u7801\u7684\u653b\u51fb\uff0c\u6700\u7b80\u5355\u7684\u65b9\u5f0f\u5c31\u662f\u66f4\u6539ssh\u7aef\u53e3\u53f7\uff0c\u7531\u4e8e\u7cfb\u7edf\u7684\u53d8\u66f4\uff0ccentos7\u76f8\u6bd4centos6\u7684\u66f4\u6539\u65b9\u5f0f\u6709\u70b9\u53d8\u5316\uff0c\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u7f16\u8f91\/etc\/ssh\/sshd_config\u6587\u4ef6\uff0c\u628a#Port 22\u7684\u6ce8\u91ca\u53bb\u6389\uff0c\u66f4\u6539\u4e3aPort 7251\uff08\u8fd9\u4e2a\u5177\u4f53\u7684\u7aef\u53e3\u53f7\u968f\u81ea\u5df1\u559c\u6b22\u6539\uff09<\/li>\n<li>CentOS7\u9ed8\u8ba4\u662f\u542f\u7528selinux\u52a0\u56fa\u7684\uff0c\u6240\u4ee5\u66f4\u6539\u540e\uff0c\u5fc5\u987b\u8981\u8ba9selinux\u77e5\u9053\u65b0\u7684ssh\u7aef\u53e3\uff0c\u6b64\u5904\u4f7f\u7528semanage\u547d\u4ee4\u3002<\/li>\n<li>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u6700\u5c0f\u5316\u5b89\u88c5\u7684CentOS\u4e2d\uff0csemanage\u547d\u4ee4\u662f\u7f3a\u5931\u7684\uff0c\u65e0\u6cd5\u6b63\u5e38\u4f7f\u7528\uff0c\u5fc5\u987b\u5148\u5b89\u88c5yum install policycoreutils-python\u3002<\/li>\n<li>\u4f7f\u7528semanage port -a -t ssh_port_t -p tcp 7251\uff0c\u6267\u884c\u6b64\u6761\u547d\u4ee4\u4e4b\u540e\uff0cselinux\u5c31\u5141\u8bb8ssh\u76d1\u542c7251\u7aef\u53e3\u4e86\u3002<\/li>\n<li>\u901a\u8fc7semanage port -l | grep ssh\uff0c\u68c0\u67e5\u8fd9\u4e2aselinux\u8bbe\u7f6e\u662f\u5426\u751f\u6548\u3002<\/li>\n<li>\u6b64\u65f6\uff0c\u9ed8\u8ba4\u768422\u7684\u7aef\u53e3\u5df2\u7ecf\u4e0d\u9700\u8981\u4e86\uff0c\u5c1d\u8bd5\u5220\u966422\u7684\u7aef\u53e3\u3002semanage port -d -t ssh_port_t -p tcp 22\uff0c\u4f1a\u63d0\u793a\u5931\u8d25\uff0c\u4e8b\u5b9e\u4e0a\uff0c\u9ed8\u8ba4\u7684\u7aef\u53e3\u662f\u65e0\u6cd5\u4eceselinux\u5220\u9664\u7684\u3002<\/li>\n<li>\u63a5\u4e0b\u6765\u8bbe\u7f6e\u9632\u706b\u5899<span class=\"crayon-r\">cp<\/span> <span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">usr<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">lib<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">firewalld<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">services<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">ssh<\/span><span class=\"crayon-e\">.xml<\/span> <span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">etc<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">firewalld<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">services<\/span><span class=\"crayon-o\">\/<\/span>\uff0c\u7f16\u8f91<span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">etc<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">firewalld<\/span><span class=\"crayon-o\">\/<\/span><span class=\"crayon-v\">services<\/span><span class=\"crayon-o\">\/ssh.xml\uff0c\u628a22\u7aef\u53e3\u6539\u62107251.<br \/>\n<\/span><\/li>\n<li>\u91cd\u65b0\u52a0\u8f7d\u4e0b\u9632\u706b\u5899\u914d\u7f6e\uff0cfirewall-cmd &#8211;reload\u3002<\/li>\n<li>\u63a5\u4e0b\u6765\u91cd\u542f\u4e0bsystemctl start sshd.service\u3002\u8fd9\u6837\u5e94\u8be5\u7aef\u53e3\u66f4\u6362\u5c31\u6210\u529f\u4e86\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u7684linux\u670d\u52a1\u5668\u7ecf\u5e38\u767b\u5f55\u540e\u4f1a\u53d7\u5230\u8fd9\u6837\u7684\u63d0\u793a\uff1a Last failed lo<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25"}],"version-history":[{"count":5,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions\/145"}],"wp:attachment":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}