{"id":581572,"date":"2006-12-27T10:16:00","date_gmt":"2006-12-27T10:16:00","guid":{"rendered":"http:\/\/jianpi.yo2.cn\/articles\/%e6%94%be%e5%81%87%e5%89%8d%e7%94%b5%e8%84%91%e5%ad%a6%e4%b9%a0%e8%ae%a1%e5%88%92.html"},"modified":"2025-11-10T14:40:05","modified_gmt":"2025-11-10T06:40:05","slug":"%e6%94%be%e5%81%87%e5%89%8d%e7%94%b5%e8%84%91%e5%ad%a6%e4%b9%a0%e8%ae%a1%e5%88%92","status":"publish","type":"post","link":"http:\/\/puo.cn\/?p=581572","title":{"rendered":"SSH\u73af\u5883\u4e0b\uff0c\u5982\u4f55\u76f4\u63a5 \u6dfb\u52a0\u670d\u52a1\u5668\u7aef\u53e3\u5462"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>\u5728 SSH \u73af\u5883\u4e0b\u76f4\u63a5\u4e3a\u670d\u52a1\u5668\u6dfb\u52a0\u7aef\u53e3\uff0c\u9700\u901a\u8fc7**\u9632\u706b\u5899\u914d\u7f6e**\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u5e38\u89c1 Linux \u53d1\u884c\u7248\u7684\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\uff1a<\/p>\n<p>&#8212;<\/p>\n<p>### **\u4e00\u3001\u786e\u5b9a\u9632\u706b\u5899\u5de5\u5177**<br \/>\n&#8211; **CentOS 7+\/RHEL 8+**: \u4f7f\u7528 `firewalld`<br \/>\n&#8211; **Ubuntu\/Debian**: \u4f7f\u7528 `ufw` \u6216 `iptables`<br \/>\n&#8211; **\u65e7\u7248\u672c CentOS\/RedHat**: \u4f7f\u7528 `iptables`<\/p>\n<p>&#8212;<\/p>\n<p>### **\u4e8c\u3001\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4**<\/p>\n<p>#### **1. \u4f7f\u7528 firewalld (CentOS 7+)**<br \/>\n&#8220;`bash<br \/>\n# 1. \u6dfb\u52a0\u7aef\u53e3\uff08\u4ee5 8080 \u4e3a\u4f8b\uff09<br \/>\nsudo firewall-cmd &#8211;zone=public &#8211;add-port=8080\/tcp &#8211;permanent<\/p>\n<p># 2. \u91cd\u8f7d\u9632\u706b\u5899\u4f7f\u914d\u7f6e\u751f\u6548<br \/>\nsudo firewall-cmd &#8211;reload<\/p>\n<p># 3. \u9a8c\u8bc1\u7aef\u53e3\u662f\u5426\u5f00\u653e<br \/>\nsudo firewall-cmd &#8211;list-ports<br \/>\n&#8220;`<\/p>\n<p>#### **2. \u4f7f\u7528 ufw (Ubuntu\/Debian)**<br \/>\n&#8220;`bash<br \/>\n# 1. \u542f\u7528 ufw\uff08\u82e5\u672a\u542f\u7528\uff09<br \/>\nsudo ufw enable<\/p>\n<p># 2. \u5141\u8bb8\u7aef\u53e3\uff08\u4ee5 8080 \u4e3a\u4f8b\uff09<br \/>\nsudo ufw allow 8080\/tcp<\/p>\n<p># 3. \u9a8c\u8bc1\u72b6\u6001<br \/>\nsudo ufw status<br \/>\n&#8220;`<\/p>\n<p>#### **3. \u4f7f\u7528 iptables (\u901a\u7528\u65b9\u6848)**<br \/>\n&#8220;`bash<br \/>\n# 1. \u6dfb\u52a0\u5141\u8bb8\u89c4\u5219\uff08\u4ee5 8080 \u4e3a\u4f8b\uff09<br \/>\nsudo iptables -A INPUT -p tcp &#8211;dport 8080 -j ACCEPT<\/p>\n<p># 2. \u4fdd\u5b58\u89c4\u5219\uff08\u9632\u6b62\u91cd\u542f\u5931\u6548\uff09<br \/>\n# &#8211; Debian\/Ubuntu: sudo apt install iptables-persistent; sudo netfilter-persistent save<br \/>\n# &#8211; CentOS\/RHEL: sudo service iptables save<br \/>\n&#8220;`<\/p>\n<p>&#8212;<\/p>\n<p>### **\u4e09\u3001\u5173\u952e\u6ce8\u610f\u4e8b\u9879**<br \/>\n1. **\u6743\u9650\u8981\u6c42**\uff1a\u6240\u6709\u547d\u4ee4\u9700\u4ee5 `root` \u6743\u9650\u6267\u884c\uff08\u4f7f\u7528 `sudo`\uff09\u3002<br \/>\n2. **\u7aef\u53e3\u51b2\u7a81**\uff1a\u786e\u4fdd\u76ee\u6807\u7aef\u53e3\u672a\u88ab\u5176\u4ed6\u670d\u52a1\u5360\u7528\uff08\u53ef\u901a\u8fc7 `netstat -tuln | grep \u7aef\u53e3\u53f7` \u68c0\u67e5\uff09\u3002<br \/>\n3. **\u5b89\u5168\u52a0\u56fa**\uff1a<br \/>\n&#8211; \u82e5\u4ec5\u9700\u7279\u5b9a IP \u8bbf\u95ee\uff0c\u53ef\u6dfb\u52a0\u767d\u540d\u5355\uff08\u4f8b\u5982 `firewalld` \u4e2d\u4f7f\u7528 `&#8211;add-rich-rule=&#8221;rule family=&#8217;ipv4&#8242; source address=&#8217;192.168.1.100&#8242; port port=8080 protocol=&#8217;tcp&#8217; accept&#8221;`\uff09\u3002<br \/>\n&#8211; \u907f\u514d\u5f00\u653e\u4e0d\u5fc5\u8981\u7684\u7aef\u53e3\uff0c\u964d\u4f4e\u5b89\u5168\u98ce\u9669\u3002<br \/>\n4. **\u670d\u52a1\u91cd\u542f**\uff1a\u82e5\u7aef\u53e3\u5bf9\u5e94\u7279\u5b9a\u670d\u52a1\uff08\u5982 Nginx\u3001Tomcat\uff09\uff0c\u9700\u91cd\u542f\u670d\u52a1\u4f7f\u5176\u76d1\u542c\u65b0\u7aef\u53e3\u3002<\/p>\n<p>&#8212;<\/p>\n<p>### **\u56db\u3001\u9a8c\u8bc1\u7aef\u53e3\u5f00\u653e**<br \/>\n&#8220;`bash<br \/>\n# \u4ece\u672c\u5730\u6d4b\u8bd5\u7aef\u53e3\u8fde\u901a\u6027<br \/>\ntelnet \u4f60\u7684\u670d\u52a1\u5668IP \u7aef\u53e3<\/p>\n<p># \u6216\u4f7f\u7528 curl<br \/>\ncurl http:\/\/\u4f60\u7684\u670d\u52a1\u5668IP:\u7aef\u53e3<br \/>\n&#8220;`<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5373\u53ef\u5728 SSH \u73af\u5883\u4e0b\u5feb\u901f\u4e3a\u670d\u52a1\u5668\u6dfb\u52a0\u7aef\u53e3\u3002\u6839\u636e\u5b9e\u9645\u4f7f\u7528\u7684\u9632\u706b\u5899\u5de5\u5177\u9009\u62e9\u5bf9\u5e94\u7684\u547d\u4ee4\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u5728 SSH \u73af\u5883\u4e0b\u76f4\u63a5\u4e3a\u670d\u52a1\u5668\u6dfb\u52a0\u7aef\u53e3\uff0c\u9700\u901a\u8fc7**\u9632\u706b\u5899\u914d\u7f6e**\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u5e38\u89c1 Linux \u53d1\u884c\u7248\u7684\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\uff1a &#8212; ### **\u4e00\u3001\u786e\u5b9a\u9632\u706b\u5899\u5de5\u5177** &#8211; **CentOS 7+\/RHEL 8+*&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128],"tags":[151,917,918],"topic":[],"class_list":["post-581572","post","type-post","status-publish","format-standard","hentry","category-128","tag-centos","tag-917","tag-918"],"_links":{"self":[{"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/posts\/581572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=581572"}],"version-history":[{"count":3,"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/posts\/581572\/revisions"}],"predecessor-version":[{"id":655512,"href":"http:\/\/puo.cn\/index.php?rest_route=\/wp\/v2\/posts\/581572\/revisions\/655512"}],"wp:attachment":[{"href":"http:\/\/puo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=581572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=581572"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=581572"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/puo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=581572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}