{"id":36840,"date":"2024-11-26T15:12:55","date_gmt":"2024-11-26T07:12:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36840\/"},"modified":"2024-11-26T15:12:55","modified_gmt":"2024-11-26T07:12:55","slug":"linux%e4%b8%ad%e4%bf%ae%e6%94%b9ssh%e7%ab%af%e5%8f%a3%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36840\/","title":{"rendered":"Linux\u4e2d\u4fee\u6539SSH\u7aef\u53e3\u53f7"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/172714807944465.jpg\" class=\"aligncenter\" title=\"Linux\u4e2d\u4fee\u6539SSH\u7aef\u53e3\u53f7\u63d2\u56fe\" alt=\"Linux\u4e2d\u4fee\u6539SSH\u7aef\u53e3\u53f7\u63d2\u56fe\" \/><\/p>\n<p>vps\u4e00\u5230\u624b\uff0c\u7b2c\u4e00\u4ef6\u4e8b\u5c31\u662f\u66f4\u6539ssh\u7aef\u53e3\uff0c\u4f7f\u7528\u4e00\u4e2a\u4e0d\u5bb9\u6613\u88ab\u62c6\u89e3\u7684\u7aef\u53e3\u53f7\uff0c\u9632\u6b62\u88ab\u9ed1\u3002<\/p>\n<p>\u66f4\u6539\u7aef\u53e3\u53f7\u662f\u901a\u8fc7\u4fee\u6539SSH\u7684\u914d\u7f6e\u6587\u4ef6\u5b9e\u73b0\u7684\uff0c\u767b\u5f55ssh\u540e\uff0c\u8f93\u5165\uff1a<\/p>\n<pre>vim \/etc\/ssh\/sshd_config<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5411\u4e0b\u627e\u5230<span style=\"padding: 4px 8px;font-size: 12px;border-radius: 3px;color: #c7254e;background-color: #f9f2f4\">#Port 22<\/span>\u8fd9\u6bb5<\/p>\n<p>\u8fdb\u5165vi\u63d2\u5165\u6a21\u5f0f\uff0c\u8fdb\u884c\u7f16\u8f91<\/p>\n<p>\u5220\u9664\u6389Port 22\u524d\u9762\u7684#\uff0c\u7136\u540e\u4e0b\u4e00\u884c\u8f93\u5165\u65b0\u7684\u7aef\u53e3\u53f7\u5982\uff1aPort 10000\uff08\u8fd9\u4e2a\u4f60\u81ea\u5df1\u5b9a\uff0c\u6700\u5927\u4e0d\u80fd\u8d85\u8fc765535\uff09<\/p>\n<p>\u7f16\u8f91\u597d\uff0c\u5148\u6309ESC\u952e\uff0c\u518d\u8f93\u5165 :wq&nbsp; \u4fdd\u5b58\u9000\u51fa.<\/p>\n<p>\u63a5\u7740\u91cd\u65b0\u542f\u52a8ssh\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\/etc\/init.d\/sshd restart<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\u4f7f\u752810000\u7aef\u53e3\u767b\u5f55\uff0c\u770b\u662f\u5426\u53ef\u4ee5\u8fde\u63a5\u6210\u529f\uff0c\u8fde\u63a5\u6210\u529f\u540e\u5728\u5220\u966422\u7aef\u53e3.<\/p>\n<p>\u4e0d\u8fc7\u5728\u8fd9\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u4e00\u822c\u7684\u670d\u52a1\u5668\u90fd\u6709\u81ea\u5e26\u7684\u9632\u706b\u5899iptables\u89c4\u5219\uff0c\u628a\u7aef\u53e310000 \u5728\u89c4\u5219\u4e2d\u8bbe\u7f6e\u5907\u653e\u884c\u3002<\/p>\n<pre>iptables -I INPUT&nbsp; -p tcp --dport 10000 -j ACCEPT<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u53c2\u6570 -I&nbsp; \u662f\u628a\u4e0a\u9762\u90a3\u6761\u89c4\u5219\u63d2\u5165\u5230iptables\u89c4\u5219\u7684\u6700\u524d\u9762\uff0c\u7136\u540e\u5220\u9664ssh\u9ed8\u8ba4\u768422\u7aef\u53e3\uff0c\u4fdd\u5b58\u89c4\u5219\uff0c\u91cd\u542f\u9632\u706b\u5899\uff0c\u5230\u6b64\u5927\u529f\u544a\u6210\u3002<\/p>\n<p>\u4e0b\u9762\u8bf4\u4e00\u4e0b\uff0c\u600e\u4e48\u5220\u9664iptables\u89c4\u5219\uff0c\u6709\u65f6\u5019\u6709\u4e9b\u89c4\u5219\u592a\u957f\uff0c\u5220\u9664\u65f6\u8981\u5199\u4e00\u5927\u4e32\uff0c\u65e2\u6d6a\u8d39\u65f6\u95f4\u53c8\u5bb9\u6613\u5199\u9519\uff0c\u8fd9\u65f6\u6211\u4eec\u53ef\u4ee5\u5148\u4f7f\u7528\u2013line-number\u67e5\u770b\u51fa\u8be5\u6761\u89c4\u5219\u7684\u884c\u53f7\uff0c\u518d\u901a\u8fc7\u884c\u53f7\u5220\u9664\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>[root@test ~]# iptables -nL --line-number\nChain INPUT (policy ACCEPT)\nnum&nbsp; target&nbsp;&nbsp;&nbsp;&nbsp; prot opt source&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; destination\n1&nbsp;&nbsp;&nbsp; DROP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; all&nbsp; --&nbsp; 192.168.1.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.0.0.0\/0\n2&nbsp;&nbsp;&nbsp; DROP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; all&nbsp; --&nbsp; 192.168.1.2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.0.0.0\/0\n3&nbsp;&nbsp;&nbsp; DROP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; all&nbsp; --&nbsp; 192.168.1.3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.0.0.0\/0\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6bd4\u5982\u5220\u9664\u7b2c\u4e8c\u6761\u89c4\u5219\uff0c\u8f93\u5165 \uff1a<\/p>\n<pre>[root@test ~]# iptables -D INPUT 2<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fLinux\u4e2d\u4fee\u6539SSH\u7aef\u53e3\u53f7\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>vps\u4e00\u5230\u624b\uff0c\u7b2c\u4e00\u4ef6\u4e8b\u5c31\u662f\u66f4\u6539ssh\u7aef\u53e3\uff0c\u4f7f\u7528\u4e00\u4e2a\u4e0d\u5bb9\u6613\u88ab\u62c6\u89e3\u7684\u7aef\u53e3\u53f7\uff0c\u9632\u6b62\u88ab\u9ed1\u3002 \u66f4\u6539\u7aef\u53e3\u53f7\u662f\u901a\u8fc7\u4fee\u6539SSH\u7684\u914d\u7f6e\u6587\u4ef6\u5b9e\u73b0\u7684\uff0c\u767b\u5f55ssh\u540e\uff0c\u8f93\u5165\uff1a vim \/etc\/ssh\/sshd_config \u767b\u5f55\u540e\u590d\u5236 \u5411\u4e0b\u627e\u5230#Port 22\u8fd9\u6bb5 \u8fdb\u5165vi\u63d2\u5165\u6a21\u5f0f\uff0c\u8fdb\u884c\u7f16\u8f91 \u5220\u9664\u6389Port 22\u524d\u9762\u7684#\uff0c\u7136\u540e\u4e0b\u4e00\u884c\u8f93\u5165\u65b0\u7684\u7aef\u53e3\u53f7\u5982\uff1aPort 10000\uff08\u8fd9\u4e2a\u4f60\u81ea\u5df1\u5b9a\uff0c\u6700\u5927\u4e0d\u80fd\u8d85\u8fc765535\uff09 \u7f16\u8f91\u597d\uff0c\u5148\u6309ESC\u952e\uff0c\u518d\u8f93\u5165 :wq&nbsp; \u4fdd\u5b58\u9000\u51fa. \u63a5\u7740\u91cd\u65b0\u542f\u52a8ssh\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a \/etc\/init.d\/sshd restart \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\u4f7f\u752810000\u7aef\u53e3\u767b\u5f55\uff0c\u770b\u662f\u5426\u53ef\u4ee5\u8fde\u63a5\u6210\u529f\uff0c\u8fde\u63a5\u6210\u529f\u540e\u5728\u5220\u966422\u7aef\u53e3. \u4e0d\u8fc7\u5728\u8fd9\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u4e00\u822c\u7684\u670d\u52a1\u5668\u90fd\u6709\u81ea\u5e26\u7684\u9632\u706b\u5899iptables\u89c4\u5219\uff0c\u628a\u7aef\u53e310000 \u5728\u89c4\u5219\u4e2d\u8bbe\u7f6e\u5907\u653e\u884c\u3002 iptables -I INPUT&nbsp; -p tcp &#8211;dport 10000 -j ACCEPT \u767b\u5f55\u540e\u590d\u5236 \u53c2\u6570 -I&nbsp; \u662f\u628a\u4e0a\u9762\u90a3\u6761\u89c4\u5219\u63d2\u5165\u5230iptables\u89c4\u5219\u7684\u6700\u524d\u9762\uff0c\u7136\u540e\u5220\u9664ssh\u9ed8\u8ba4\u768422\u7aef\u53e3\uff0c\u4fdd\u5b58\u89c4\u5219\uff0c\u91cd\u542f\u9632\u706b\u5899\uff0c\u5230\u6b64\u5927\u529f\u544a\u6210\u3002 \u4e0b\u9762\u8bf4\u4e00\u4e0b\uff0c\u600e\u4e48\u5220\u9664iptables\u89c4\u5219\uff0c\u6709\u65f6\u5019\u6709\u4e9b\u89c4\u5219\u592a\u957f\uff0c\u5220\u9664\u65f6\u8981\u5199\u4e00\u5927\u4e32\uff0c\u65e2\u6d6a\u8d39\u65f6\u95f4\u53c8\u5bb9\u6613\u5199\u9519\uff0c\u8fd9\u65f6\u6211\u4eec\u53ef\u4ee5\u5148\u4f7f\u7528\u2013line-number\u67e5\u770b\u51fa\u8be5\u6761\u89c4\u5219\u7684\u884c\u53f7\uff0c\u518d\u901a\u8fc7\u884c\u53f7\u5220\u9664\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a [root@test ~]# iptables -nL &#8211;line-number Chain INPUT (policy ACCEPT) num&nbsp; target&nbsp;&nbsp;&nbsp;&nbsp; prot opt source&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; destination 1&nbsp;&nbsp;&nbsp; DROP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; all&nbsp; &#8212;&nbsp; 192.168.1.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-36840","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=36840"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36840\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}