{"id":438,"date":"2015-12-28T03:46:14","date_gmt":"2015-12-27T19:46:14","guid":{"rendered":"http:\/\/wp.iur.me\/?p=438"},"modified":"2022-11-06T20:14:48","modified_gmt":"2022-11-06T12:14:48","slug":"ssh%e9%bb%98%e8%ae%a4%e7%ab%af%e5%8f%a3%e4%bf%ae%e6%94%b9","status":"publish","type":"post","link":"https:\/\/www.iur.me\/?p=438","title":{"rendered":"SSH\u9ed8\u8ba4\u7aef\u53e3\u4fee\u6539"},"content":{"rendered":"<p>SSH \u7aef\u53e3\u9ed8\u8ba4\u662f22. \u4f46\u4ece\u5b89\u5168\u65b9\u9762\u8003\u8651\uff0c\u5efa\u8bae\u4fee\u6539\u8fd9\u4e2a\u7aef\u53e3\u3002 \u7aef\u53e3\u7684\u53d6\u503c\u8303\u56f4\u662f 0 &#8211; 65535(\u53732\u768416\u6b21\u65b9)\uff0c0\u52301024\u662f\u7cfb\u7edf\u4f7f\u7528\u7684\u7aef\u53e3\uff0c\u5982 http\u670d\u52a1\u7684\u7aef\u53e380\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7684\u7aef\u53e3\u8303\u56f4\uff1a1024\u523065535\u3002\u8fd9\u4e2a\u662fsocket\u89c4\u5b9a\u7684\u3002<br \/>\n<wbr \/><wbr \/><\/p>\n<p>\uff08\u6ce8\uff1a\u9996\u5148\u8bbe\u7f6e\u9632\u706b\u5899,\u8fd9\u4e00\u6b65\u4e00\u5b9a\u8981\u5148\u505a\uff0c\u4e0d\u7136\u540e\u9762\u6362\u4e86SSH\u7aef\u53e3\u8fdb\u4e0d\u53bb\u5c31\u9ebb\u70e6\uff1a<\/p>\n<pre>\n iptables -A INPUT -p tcp --dport \u65b0\u7684ssh\u7aef\u53e3 -j ACCEPT\niptables -A OUTPUT -p tcp --sport \u65b0\u7684ssh\u7aef\u53e3 -j ACCEPT<\/pre>\n<div>service iptables save<\/div>\n<div>service iptables restart<\/div>\n<div><\/div>\n<div>\u5907\u4efdssh\u7aef\u53e3\u914d\u7f6e\u6587\u4ef6\uff1a<\/div>\n<div>cp \/etc\/ssh\/ssh_config \/etc\/ssh\/ssh_config.bak<\/div>\n<div>cp \/etc\/ssh\/sshd_config \/etc\/ssh\/sshd_config.bak<\/div>\n<p>\uff09<br \/>\n<wbr \/><wbr \/><br \/>\n\u4e00.\u00a0<wbr \/><wbr \/> Linux\u4fee\u6539ssh\u7aef\u53e322<br \/>\n1.1 \u4fee\u6539\u7aef\u53e3\u914d\u7f6e\u6587\u4ef6\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/><br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> vi \/etc\/ssh\/ssh_config<br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> vi \/etc\/ssh\/sshd_config<br \/>\n<wbr \/><wbr \/><br \/>\n\u53d6\u6d88Port\u524d\u7684#\u6ce8\u91ca\uff0c\u5e76\u5c06\u7aef\u53e322\u6539\u621065535\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/><\/p>\n<p>\u5982\u679c\u662f\u4e0d\u662f\u589e\u52a0\uff0c\u800c\u662f\u4fee\u6539\u7aef\u53e3\u7684\u8bdd\uff0c\u5efa\u8bae\u5148\u4fdd\u755922\u7aef\u53e3\uff0c\u7b49\u65b0\u7aef\u53e3\u53ef\u4ee5\u767b\u5f55\u518d\u53bb\u6389\u3002<\/p>\n<p><wbr \/><wbr \/><br \/>\n<wbr \/><wbr \/><br \/>\n1.2 \u91cd\u542fsshd\u670d\u52a1<br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> \u7528root\u7528\u6237\u6267\u884c\uff1a<br \/>\n[root@singledb ~]# service sshd restart<br \/>\nStopping sshd:\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> [\u00a0<wbr \/><wbr \/> OK\u00a0<wbr \/><wbr \/> ]<br \/>\nStarting sshd:\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> [\u00a0<wbr \/><wbr \/> OK\u00a0<wbr \/><wbr \/> ]<br \/>\n<wbr \/><wbr \/><br \/>\n\u6b64\u65f6\u5728\u7528SSH\u8fde\u63a5\uff0c\u5c31\u9700\u8981\u4fee\u6539ssh \u7684\u7aef\u53e3\u4e3a6535\u624d\u80fd\u8fde\u63a5\u4e86\u3002<br \/>\n<wbr \/><wbr \/>\u6ce8\u610f\uff1a\u8fd9\u4e9b\u4fee\u6539\u4e0d\u5f71\u54cd\u5df2\u7ecf\u8fde\u63a5\u7684SSH\u3002\u53ea\u5bf9\u4ee5\u540e\u7684\u7684\u8fde\u63a5\u4ea7\u751f\u5f71\u54cd\u3002<\/p>\n<p>\u5220\u966422\u7aef\u53e3<br \/>\niptables -D INPUT -p tcp &#8211;dport 22 -j ACCEPT<\/p>\n<p>\u603b\u7ed3\uff1a<\/p>\n<p>\u4e24\u6b65\u8d70\uff1a<\/p>\n<p>\u4e00\uff1a\u4fee\u6539sshd\u914d\u7f6e\u6587\u4ef6\uff0c\u6dfb\u52a0\u4fee\u6539\u7aef\u53e3<\/p>\n<p>\u4e8c\uff1a\u9632\u706b\u5899\u5141\u8bb8\uff1aiptables -A INPUT -m state \u2013state NEW -m tcp -p tcp \u2013dport 234 -j ACCEPT<\/p>\n<p>\u9644\uff1a\u7981\u7528Root \u8fdc\u7a0b\u767b\u9646\u64cd\u4f5c\u65b9\u6cd5<\/p>\n<p><wbr \/><br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> \u5148\u5728ssh\u7684\u914d\u7f6e\u6587\u4ef6\u91cc\u4fee\u6539Root \u8fdc\u7a0b\u767b\u9646\u53c2\u6570\u3002 \u7981\u7528root\u8fdc\u7a0b\u767b\u9646\u3002 \u7136\u540e\u521b\u5efa\u4e00\u4e2a\u8fdc\u7a0b\u767b\u9646\u7528\u6237\u3002\u7528\u8fd9\u4e2a\u7528\u6237\u767b\u9646\u4e4b\u540e\uff0c\u5728\u5207\u6362\u5230root\u7528\u6237\uff0c\u62ff\u5230\u6700\u9ad8\u6743\u9650\u3002<br \/>\n<wbr \/><wbr \/><br \/>\n2.1 \u521b\u5efa\u666e\u901a\u6743\u9650\u7684\u7528\u6237<br \/>\n[root@singledb ~]# useradd ruser<br \/>\n[root@singledb ~]# passwd ruser<br \/>\nChanging password for user ruser.<br \/>\nNew UNIX password:<br \/>\nBAD PASSWORD: it is too short<br \/>\nRetype new UNIX password:<br \/>\npasswd: all authentication tokens updated successfully.<br \/>\n[root@singledb ~]#<br \/>\n<wbr \/><wbr \/><br \/>\n2.2 \u7981\u6b62ROOT\u8fdc\u7a0bSSH\u767b\u5f55<br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> #vi \/etc\/ssh\/sshd_config<br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> \u628a<br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> PermitRootLogin yes<br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> \u6539\u4e3a<br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> PermitRootLogin no<br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/><br \/>\n2.3\u00a0<wbr \/><wbr \/> \u91cd\u542fsshd\u670d\u52a1<br \/>\n<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/>\u00a0<wbr \/><wbr \/> #service sshd restart<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SSH \u7aef\u53e3\u9ed8\u8ba4\u662f22. \u4f46\u4ece\u5b89\u5168\u65b9\u9762\u8003\u8651\uff0c\u5efa\u8bae\u4fee\u6539\u8fd9\u4e2a\u7aef\u53e3\u3002 \u7aef\u53e3\u7684\u53d6\u503c\u8303\u56f4\u662f 0 &#8211; 6553 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-438","post","type-post","status-publish","format-standard","hentry","category-it"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts\/438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=438"}],"version-history":[{"count":1,"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts\/438\/revisions"}],"predecessor-version":[{"id":725,"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts\/438\/revisions\/725"}],"wp:attachment":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}