{"id":111,"date":"2023-06-05T12:58:11","date_gmt":"2023-06-05T04:58:11","guid":{"rendered":"http:\/\/pro369.com\/linux\/?p=111"},"modified":"2019-05-09T03:31:00","modified_gmt":"2019-05-09T03:31:00","slug":"sshd-%e5%ae%89%e5%85%a8%e8%a8%ad%e5%ae%9a-%28-%e8%a8%ad%e5%ae%9a%e7%a6%81%e6%ad%a2%e4%bd%bf%e7%94%a8ssh%e5%90%8d%e5%96%ae-%29","status":"publish","type":"post","link":"https:\/\/por.tw\/linux\/sshd-%e5%ae%89%e5%85%a8%e8%a8%ad%e5%ae%9a-%28-%e8%a8%ad%e5%ae%9a%e7%a6%81%e6%ad%a2%e4%bd%bf%e7%94%a8ssh%e5%90%8d%e5%96%ae-%29\/","title":{"rendered":"sshd \u5b89\u5168\u8a2d\u5b9a ( \u8a2d\u5b9a&#8221;\u7981\u6b62\u4f7f\u7528ssh\u540d\u55ae&#8221; )"},"content":{"rendered":"<p><strong>sshd \u5b89\u5168\u8a2d\u5b9a ( \u8a2d\u5b9a&quot;\u7981\u6b62\u4f7f\u7528ssh\u540d\u55ae&quot; )<\/p>\n<p> SSH \u4f3a\u670d\u5668\u7684\u8a2d\u5b9a\u6a94\u662f \/etc\/ssh\/sshd_config\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b SSH \u7684\u5b89\u5168\u914d\u7f6e:<\/p>\n<p> \u70ba\u4e86\u52a0\u5f37SSH\u5b89\u5168\u6027, \u9664\u4e86\u9650\u5236root\u5e33\u865f\u767b\u5165\u9019\u7a2e\u5fc5\u5099\u7684\u624b\u6bb5\u4e4b\u5916, \u9084\u53c3\u7167\u4e86\u524d\u8f29\u5011\u7684\u505a\u6cd5, \u5f9e\u4e09\u90e8\u5206\u4f86\u8457\u624b:<br \/> <\/strong><br \/> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/visdacom.com\/linux\/wp-content\/uploads\/2013\/04\/9801102283.png\"  width=\"359\" height=\"538\" \/><strong><\/p>\n<p> \u4e00. sshd_config \u90e8\u5206<\/p>\n<p> \u9019\u662f\u4e00\u500b\u5f88\u7c21\u55ae\u7684\u8a2d\u5b9a\u624b\u6bb5, \u9664\u4e86\u9650\u5236root\u4e4b\u5916, \u9084\u9806\u4fbf\u9650\u5236\u9023\u7dda\u6578, \u5982\u4e0b:<\/p>\n<p> #LoginGraceTime 2m<br \/> PermitRootLogin no<br \/> #StrictModes yes<br \/> MaxAuthTries 2<\/p>\n<p> # To disable tunneled clear text passwords, change to no here!<br \/> #PasswordAuthentication yes<br \/> PermitEmptyPasswords no<br \/> PasswordAuthentication yes<\/p>\n<p> # ChallengeResponseAuthentication=no<br \/> #UsePAM no<br \/> UsePAM yes<\/p>\n<p> 1. SSH \u9810\u8a2d\u6703\u4f7f\u7528 Port 22\uff0c\u5c07\u5b83\u6539\u6210\u5176\u4ed6\u7684\u57e0\u865f\uff0c\u627e\u5230:<\/p>\n<p> Port 22 \u63db\u6210:<\/p>\n<p> Port new_port<\/p>\n<p> 2. \u7981\u6b62 root \u76f4\u63a5\u767b\u5165\uff0c\u5148\u8981\u767b\u5165\u4e00\u822c\u8cec\u6236\uff0c\u518d\u7528 su \u6307\u4ee4\u5207\u63db\u5230 root\uff0c\u628a PermitRootlogin \u8a2d\u6210 no:<\/p>\n<p> PermitRootlogin no<\/p>\n<p> 3. \u53ea\u7d66\u4e88\u7279\u5b9a\u4f7f\u7528\u8005\u6216\u7fa4\u7d44\u767b\u5165 SSH\uff0c\u4ee5\u4e0b\u662f\u51c6\u8a31 my_name \u4f7f\u7528\u8005\u53ca my_group \u7fa4\u7d44\u767b\u5165:<\/p>\n<p> AllowUsers my_name<br \/> AllowGroups my_group<\/p>\n<p> 4. \u7981\u6b62\u4f7f\u7528\u7a7a\u5bc6\u78bc\u767b\u5165:<\/p>\n<p> PermitEmptyPasswords no<\/p>\n<p> \u6700\u5f8c\u5132\u5b58\u6a94\u6848\uff0c\u4e26\u91cd\u65b0\u555f\u52d5 SSH \u4f3a\u670d\u5668\u3002<\/p>\n<p> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p> \u4e8c.\u5229\u7528hosts.deny\u8207hosts.allow \u8a2d\u5b9a\u53ef\u4ee5\u9023\u7dda\u7684ip:<\/p>\n<p> \u5148\u5728 \/etc\/hosts.allow \u88e1\u9762, \u8a2d\u5b9a\u54ea\u4e9bip\u662f\u53ef\u4ee5\u9023\u7dda\u7684, \u4f8b\u5982\u524d\u8f29\u5011\u6240\u8209\u4f8b\u7684:<br \/> sshd:140.128.1.123<\/p>\n<p> , \u63a5\u8457, \u518d\u5230 \/etc\/hosts.deny \u88e1\u9762\u8a2d\u5b9a\u62d2\u7d55\u6240\u6709ip\u9023\u7dda:<br \/> sshd:all<\/p>\n<p> \u65bc\u662f, \u5c31\u53ea\u6709\u5728 \/etc\/hosts.allow \u6e05\u55ae\u88e1\u9762\u7684IP, \u624d\u53ef\u4ee5\u4f7f\u7528ssh \u4f86\u4e3b\u6a5f\u9023\u7dda, \u5176\u9918\u90fd\u6703\u88ab\u62d2\u7d55\u6389.<\/p>\n<p> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p> \u4e09. \u5229\u7528pam\u6a5f\u5236:<\/p>\n<p> \u5728\u6700\u4e0a\u9762\u90a3\u6587\u7ae0\u88e1\u9762\u63d0\u5230, \u5229\u7528pam\u6a5f\u5236, \u8b93sshd\u63a5\u5230\u9023\u7dda\u6642, \u5148\u6aa2\u67e5\u662f\u5426\u5728\u9ed1\u540d\u55ae\u4e4b\u4e2d\u7684\u505a\u6cd5. \u65b9\u6cd5\u5f88\u7c21\u55ae, \u5c31\u662f\u5728\/etc\/pam.d\/ssh\u88e1\u9762\u589e\u52a0\u4e0b\u9762\u7684\u8a2d\u5b9a:<\/p>\n<p> auth required pam_stack.so service=system-auth<br \/> auth required \/lib\/security\/pam_listfile.so item=user sense=deny file=\/etc\/sshd_user_deny_list onerr=succeed<br \/> account required pam_nologin.so<br \/> account required pam_stack.so service=system-auth<br \/> password required pam_stack.so service=system-auth<br \/> session required pam_stack.so service=system-auth<\/p>\n<p> session required pam_loginuid.so<\/p>\n<p> (\u7279\u5225\u6ce8\u610f, \u4e0a\u9762\u8a2d\u5b9a\u90fd\u662f\u540c\u4e00\u884c, \u4e26\u7121\u65b7\u884c)<br \/> \u7279\u5225\u65b0\u589e\u7684\u662f\u7d05\u8272\u5b57\u7684\u90e8\u5206. \u7576\u4f60\u7684\u540d\u5b57\u5728\u8a72\u6a94\u6848( \/etc\/sshd_user_deny_list )\u4e4b\u4e2d\u6642, \u5c31\u7121\u6cd5\u5229\u7528ssh\u4f86\u767b\u5165\u7cfb\u7d71.<\/p>\n<p> \u5229\u7528\u4ee5\u4e0a\u4e09\u500b\u65b9\u6cd5, \u53ef\u4ee5\u8b93\u4f60\u7684\u4e3b\u6a5f\u5728\u63d0\u4f9bsshd\u9023\u7dda\u7684\u6642\u5019, \u5b89\u5168\u5ea6\u63d0\u5347\u4e0d\u5c11. \u4f46\u5207\u8a18, \u7d93\u5e38\u7684\u6aa2\u67e5\u8207\u66f4\u65b0, \u6e1b\u5c11\u4e0d\u5fc5\u8981\u7684\u670d\u52d9, \u589e\u52a0\u8a31\u591a\u7684\u5b89\u5168\u9650\u5236, \u624d\u662f\u4e3b\u6a5f\u7ba1\u7406\u7684\u6700\u4f73\u7b56\u7565!<br \/> <\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>sshd \u5b89\u5168\u8a2d\u5b9a ( \u8a2d\u5b9a&quot;\u7981\u6b62\u4f7f\u7528ssh\u540d\u55ae&quot; ) SSH \u4f3a\u670d\u5668\u7684\u8a2d\u5b9a\u6a94\u662f \/etc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":485,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[20],"class_list":["post-111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/por.tw\/linux\/wp-json\/wp\/v2\/posts\/111"}],"collection":[{"href":"https:\/\/por.tw\/linux\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/por.tw\/linux\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/por.tw\/linux\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/por.tw\/linux\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":0,"href":"https:\/\/por.tw\/linux\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/por.tw\/linux\/wp-json\/wp\/v2\/media\/485"}],"wp:attachment":[{"href":"https:\/\/por.tw\/linux\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/por.tw\/linux\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/por.tw\/linux\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}