{"id":89,"date":"2019-04-21T11:41:44","date_gmt":"2019-04-21T03:41:44","guid":{"rendered":"http:\/\/www.anthonylee.cn\/myblog\/?p=89"},"modified":"2019-05-29T11:41:44","modified_gmt":"2019-05-29T03:41:44","slug":"%e6%8b%92%e7%bb%9dssh%e8%bf%9c%e7%a8%8b%e6%9a%b4%e5%8a%9b%e7%a0%b4%e8%a7%a3","status":"publish","type":"post","link":"http:\/\/www.anthonylee.cn\/myblog\/?p=89","title":{"rendered":"\u62d2\u7eddssh\u8fdc\u7a0b\u66b4\u529b\u7834\u89e3"},"content":{"rendered":"<h4>\u5982\u4f55\u5224\u65ad\u81ea\u5df1\u6b63\u5728\u906d\u53d7ssh\u66b4\u529b\u7834\u89e3<\/h4>\n<p>ssh\u767b\u5f55\u670d\u52a1\u5668\u540e\u4f7f\u7528lastb\u547d\u4ee4\uff0c\u547d\u4ee4\u4f1a\u663e\u793a\u6700\u8fd1\u9519\u8bef\u767b\u5f55\u7684\u65e5\u5fd7\uff0c\u5305\u62ec\u901a\u8fc7ssh\u670d\u52a1\u9519\u8bef\u767b\u5f55\u7684\u65e5\u5fd7\u3002<\/p>\n<div>admin ssh:notty 191.201.86.105 Thu May 3 05:11 \u2013 05:11 (00:00)<br \/>\nadmin ssh:notty 191.201.86.105 Thu May 3 05:11 \u2013 05:11 (00:00)<br \/>\nadmin ssh:notty 191.201.86.105 Thu May 3 05:11 \u2013 05:11 (00:00)<br \/>\nadmin ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nadmin ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nadmin ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nadmin ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nadmin ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nadmin ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:10 \u2013 05:10 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:09 \u2013 05:09 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:09 \u2013 05:09 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:09 \u2013 05:09 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:09 \u2013 05:09 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:09 \u2013 05:09 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:09 \u2013 05:09 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:09 \u2013 05:09 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:09 \u2013 05:09 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:09 \u2013 05:09 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:09 \u2013 05:09 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:08 \u2013 05:08 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:08 \u2013 05:08 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:08 \u2013 05:08 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:08 \u2013 05:08 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:08 \u2013 05:08 (00:00)<br \/>\nroot ssh:notty 191.201.86.105 Thu May 3 05:08 \u2013 05:08 (00:00)<\/div>\n<p>\u5982\u679c\u5f97\u5230\u548c\u6211\u4e0a\u65b9\u663e\u793a\u5dee\u4e0d\u591a\u7684\u60c5\u51b5\uff0c\u51fa\u73b0\u5927\u91cf\u7684\u8f93\u51fa\u8bf4\u660e\u4f60\u7684\u670d\u52a1\u5668\u6b63\u5728\u906d\u53d7\u9ed1\u5ba2\u4eec\u7684\u66b4\u529b\u7834\u89e3\u3002<\/p>\n<h4>\u5982\u4f55\u9632\u8303\u66b4\u529b\u7834\u89e3<\/h4>\n<h4>\u65b9\u6cd5\u4e00\uff1a\u4fee\u6539\u8fdc\u7a0b\u767b\u5f55\u7aef\u53e3<\/h4>\n<p>\u4fee\u6539\/etc\/ssh\/sshd_config\u6587\u4ef6\u4e2d\u7684Port \u5c06\u524d\u65b9\u7684#\u6ce8\u91ca\u5220\u9664\uff0c\u5e76\u5c0622\u4fee\u6539\u4e3a\u4f60\u60f3\u8981\u4f7f\u7528\u8fdc\u7a0b\u767b\u5f55\u7684\u7aef\u53e3\uff0c\u4f8b\u598254231\u3002<\/p>\n<p>\u5728\u9632\u706b\u5899\u4e0a\u6dfb\u52a0\u8fd0\u884c\u7aef\u53e3\uff1a<br \/>\n<strong>iptables -I INPUT -p tcp \u2013dport 54231 -j ACCEPT<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u4f7f\u7528\u7684ubuntu\u7cfb\u7edf\u5e76\u4f7f\u7528ufw\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\uff1a<strong>sudo ufw allow 54231<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u4f7f\u7528CentOS7\u7cfb\u7edf\u5e76\u4f7f\u7528firewalld,\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\uff1a<br \/>\n<strong>firewall-cmd\u00a0\u2013zone=public\u00a0\u2013add-port=54231\/tcp\u00a0\u2013permanent<\/strong><\/p>\n<p>\u5982\u679c\u662f\u4f7f\u7528\u4e91\u670d\u52a1\u5668\uff0c\u4e91\u670d\u52a1\u5546\u6709\u63d0\u4f9b\u5916\u90e8\u9632\u706b\u5899\uff0c\u4f8b\u5982\u963f\u91cc\u4e91\u7684\u5b89\u5168\u7ec4\u7684\u60c5\u51b5\u4e0b\u8fd8\u8981\u5728\u5916\u90e8\u7684\u5b89\u5168\u7ec4\u4e2d\u4fee\u6539\u5141\u8bb8tcp\u7aef\u53e354231\u7aef\u53e3\u7684\u7b56\u7565\u3002<\/p>\n<p>\u6700\u540e\u4f7f\u7528serivce sshd restart\u91cd\u542fsshd\u670d\u52a1\u5373\u53ef\u3002<\/p>\n<p>CentOS7\u7528\u6237\u4f7f\u7528systemctl restart sshd\u3002<\/p>\n<p>\u91cd\u542f\u670d\u52a1\u4e4b\u540e\u767b\u5f55\u670d\u52a1\u5668\u90fd\u9700\u8981\u8f93\u5165\u6307\u5b9a\u7684\u8fdc\u7a0b\u7aef\u53e3\u624d\u80fd\u591f\u767b\u5f55\u670d\u52a1\u5668\uff0c\u5927\u5927\u964d\u4f4e\u4e86\u9ed1\u5ba2\u653b\u51fb\u670d\u52a1\u5668\u7684\u6982\u7387\u3002<\/p>\n<h4>\u65b9\u6cd5\u4e8c\uff1a\u9650\u5236\u767b\u5f55IP<\/h4>\n<p>\u5982\u679c\u4f60\u7684\u516c\u53f8\u6216\u8005\u5e38\u5e38\u9700\u8981\u767b\u5f55\u670d\u52a1\u5668\u7684\u5de5\u4f5c\u7f51\u7edc\u73af\u5883\u62e5\u6709\u56fa\u5b9a\u7684IP\u5730\u5740\u65f6\uff0c\u9650\u5236\u767b\u5f55IP\u5730\u5740\u5c31\u53ef\u4ee5\u5f88\u597d\u7684\u4fdd\u62a4\u670d\u52a1\u5668\u514d\u53d7\u9ed1\u5ba2\u653b\u51fb\u3002\u5982\u679c\u6ca1\u6709\u4e0a\u8ff0\u7684\u6761\u4ef6\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7\u642d\u5efa\u5821\u5792\u673a\uff0c\u5c06\u6240\u6709\u670d\u52a1\u5668\u90fd\u8bbe\u7f6e\u4e3a\u5141\u8bb8\u5821\u5792\u673a\u7684IP\u5730\u5740\u767b\u5f55\u5373\u53ef\u4fdd\u62a4\u60a8\u7684\u670d\u52a1\u5668\u3002<\/p>\n<p>\u64cd\u4f5c\u8d77\u6765\u76f8\u5f53\u7b80\u5355\uff0c\u9996\u5148\u5728\/etc\/hosts.allow\u4e2d\u52a0\u5165\u5982\u4e0b\u4fe1\u606f\uff1a<\/p>\n<p><strong>sshd:172.16.*.*<\/strong><\/p>\n<p>\u8fd9\u6761\u4fe1\u606f\u8868\u793asshd\u670d\u52a1\u5141\u8bb8\u5411IP\u5730\u5740\u4e3a172.16\u5f00\u5934\u7684IP\u5730\u5740\u63d0\u4f9b\u670d\u52a1\u3002<\/p>\n<p>\u5176\u6b21\u5728\/etc\/hosts.deny\u4e2d\u52a0\u5165\u5982\u4e0b\u4fe1\u606f\uff1a<\/p>\n<p><strong>sshd:all:deny<\/strong><\/p>\n<p>\u8fd9\u6761\u4fe1\u606f\u8868\u793asshd\u670d\u52a1\u4e0d\u5141\u8bb8\u5411\u6240\u6709IP\u5730\u5740\u63d0\u4f9b\u670d\u52a1\u3002<\/p>\n<p>\u5982\u6b64\u4e00\u6765\u670d\u52a1\u5668\u5c06\u53ea\u6709\u6307\u5b9a\u7684IP\u5730\u5740\u53ef\u4ee5\u8bbf\u95ee\u3002<\/p>\n<h4>\u65b9\u6cd5\u4e09\uff1a\u4f7f\u7528\u975eroot\u7528\u6237\u767b\u5f55<\/h4>\n<p>\u7981\u6b62root\u7528\u6237\u767b\u5f55\u5e76\u4e14\u8bbe\u7f6e\u5141\u8bb8\u5176\u4ed6\u7528\u6237\u767b\u5f55\u540e\u5207\u6362\u81f3root\u8fdb\u884c\u64cd\u4f5c\u3002\u8fd9\u6837\u9ed1\u5ba2\u5982\u679c\u60f3\u8981\u901a\u8fc7ssh\u767b\u5f55\u670d\u52a1\u5668\u9664\u4e86\u5bc6\u7801\u4e4b\u5916\u9996\u5148\u4ed6\u8fd8\u9700\u8981\u77e5\u9053\u670d\u52a1\u5668\u5141\u8bb8\u767b\u5f55\u7684\u7528\u6237\uff0c\u8fd9\u6837\u5c06\u5927\u5927\u964d\u4f4e\u9ed1\u5ba2\u653b\u7834ssh\u7684\u53ef\u80fd\u6027\u3002<\/p>\n<p>\u9996\u5148\uff0c\u5728\u670d\u52a1\u5668\u5185\u521b\u5efa\u4e00\u4e2a\u7528\u6237\uff0clearntop:<strong>useradd learntop<\/strong><br \/>\n\u5e76\u4e14\u8bbe\u7f6e\u5bc6\u7801\uff1a<strong>passwd\u00a0learntop<\/strong>\u00a0,\u5f53\u7136\u5bc6\u7801\u9700\u8981\u5c3d\u91cf\u590d\u6742\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u9700\u8981\u5141\u8bb8\u6b64\u7528\u6237\u80fd\u591f\u4ee5root\u7528\u6237\u8eab\u4efd\u8fd0\u884c\u547d\u4ee4\u3002<br \/>\n\u4f7f\u7528<strong>visudo<\/strong>\u547d\u4ee4\u8fdb\u5165\u6587\u672c\u7f16\u8f91\u6a21\u5f0f\uff0c\u4e8e92\u884c\u9644\u8fd1<\/p>\n<div>## Syntax:<br \/>\n##<br \/>\n## user MACHINE=COMMANDS<br \/>\n##<br \/>\n## The COMMANDS section may have other options added to it.<br \/>\n##<br \/>\n## Allow root to run any commands anywhere<br \/>\nroot ALL=(ALL) ALL<br \/>\nlearntop ALL=(ALL) NOPASSWD:ALL<\/div>\n<div>\u6dfb\u52a0\u7ea2\u8272\u5b57\u4f53\u4fe1\u606f\uff1a\u201dALL=(ALL) NOPASSWD:ALL\u201d\uff0c\u4fdd\u5b58\u9000\u51fa\u540e\u53ef\u4ee5\u9a8c\u8bc1\u4e00\u4e0b\u3002<\/div>\n<div>[root@localhost ~]# visudo<br \/>\n[root@localhost ~]# su learntop<br \/>\n[<strong>learntop<\/strong>@localhost root]$ sudo su \u2013<br \/>\nLast login: Tue May 22 12:55:36 CST 2018 on pts\/1<br \/>\n[<strong>root<\/strong>@localhost ~]#whoami<br \/>\nroot<\/div>\n<div>\u9996\u5148\u4f7f\u7528<strong>su\u00a0learntop<\/strong>\u5207\u6362\u81f3learntop\u7528\u6237,\u63a5\u4e0b\u6765\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528sudo su -\u547d\u4ee4\u5207\u6362\u5230root\u7528\u6237\u3002<\/div>\n<div>\u540c\u6837\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7\u8fdc\u7a0b\u767b\u5f55\u65b9\u5f0f\u9a8c\u8bc1\uff0c\u4f7f\u7528ssh\u5ba2\u6237\u7aef\u4ee5learntop\u7528\u6237\u767b\u5f55\u7cfb\u7edf\u540e\uff0c\u518d\u4f7f\u7528sudo su -\u547d\u4ee4\u8fdb\u884c\u5207\u6362\u3002<\/div>\n<div>\u5728\u8bbe\u7f6e\u53ef\u4ee5\u901a\u8fc7learntop\u7528\u6237\u767b\u5f55\u7cfb\u7edf\u5e76\u80fd\u591f\u81ea\u7531\u5207\u6362\u81f3\u7ba1\u7406\u5458\u7528\u6237\u64cd\u4f5c\u540e\uff0c\u6211\u4eec\u9700\u8981\u7981\u6b62root\u7528\u6237\u901a\u8fc7\u8fdc\u7a0b\u65b9\u5f0f\u767b\u5f55\u7cfb\u7edf\u3002<\/div>\n<div>\u5728\/etc\/ssh\/sshd_config\u6587\u4ef6\u5185\u6dfb\u52a0\u201cPermitRootLogin no\u201d\uff0c\u540e\u91cd\u542fsshd\u670d\u52a1\u3002\u542f\u52a8\u540e\uff0croot\u7528\u6237\u5c31\u5c06\u65e0\u6cd5\u901a\u8fc7ssh\u670d\u52a1\u76f4\u63a5\u8fde\u63a5\u5230\u670d\u52a1\u5668\u3002<\/div>\n<div><\/div>\n<div>\u5f53\u7136\u9664\u6b64\u4e4b\u5916\u8fd8\u6709\u8bb8\u591a\u53ef\u4ee5\u9650\u5236\u9ed1\u5ba2\u901a\u8fc7ssh\u66b4\u529b\u7834\u89e3\u767b\u5f55\u670d\u52a1\u5668\u7684\u65b9\u6cd5\u3002\u4f8b\u5982\u4f7f\u7528\u5bc6\u94a5\u767b\u5f55\u670d\u52a1\u5668\u7b49\u3002\u4f46\u4fdd\u62a4\u6574\u4e2a\u4e1a\u52a1\u7cfb\u7edf\u7684\u5b89\u5168\u6700\u4e3a\u91cd\u8981\u7684\u4e0d\u662f\u51e0\u4e2a\u6280\u672f\u70b9\uff0c\u800c\u662f\u5728\u7ed3\u6784\u8bbe\u8ba1\u7684\u65f6\u5019\u5c31\u9884\u5148\u8003\u8651\u5230\u5b89\u5168\u7684\u56e0\u7d20\uff0c\u4f8b\u5982\u4e0d\u9700\u8981\u5411\u516c\u7f51\u63d0\u4f9b\u670d\u52a1\u7684\u670d\u52a1\u5668\u5c31\u4e0d\u8bbe\u7f6e\u516c\u7f51IP\u5730\u5740\uff0c\u914d\u7f6e\u5b89\u5168\u53ef\u9760\u7684\u5821\u5792\u673a\u3002<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5224\u65ad\u81ea\u5df1\u6b63\u5728\u906d\u53d7ssh\u66b4\u529b\u7834\u89e3 ssh\u767b\u5f55\u670d\u52a1\u5668\u540e\u4f7f\u7528lastb\u547d\u4ee4\uff0c\u547d\u4ee4\u4f1a\u663e\u793a\u6700\u8fd1\u9519\u8bef\u767b\u5f55\u7684\u65e5&hellip; <a href=\"http:\/\/www.anthonylee.cn\/myblog\/?p=89\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u62d2\u7eddssh\u8fdc\u7a0b\u66b4\u529b\u7834\u89e3<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/posts\/89"}],"collection":[{"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":1,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":90,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions\/90"}],"wp:attachment":[{"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}