{"id":33264,"date":"2026-09-17T10:00:00","date_gmt":"2026-09-17T02:00:00","guid":{"rendered":"https:\/\/cn.hostease.com\/blog\/?p=33264"},"modified":"2026-09-18T10:28:12","modified_gmt":"2026-09-18T02:28:12","slug":"ssh-port-forwarding-jump-host","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/blog\/tutorials\/ssh-port-forwarding-jump-host\/","title":{"rendered":"SSH \u7aef\u53e3\u8f6c\u53d1\u4e0e\u8df3\u677f\u673a\u914d\u7f6e\uff1a\u5b89\u5168\u8bbf\u95ee\u5185\u7f51\u670d\u52a1\u7684\u5e38\u7528\u59ff\u52bf"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/09\/ssh-port-forwarding-jump-host-cover.webp\" alt=\"SSH \u7aef\u53e3\u8f6c\u53d1\u4e0e\u8df3\u677f\u673a\u5b89\u5168\u8bbf\u95ee\u5185\u7f51\u670d\u52a1\u7684\u5c01\u9762\u56fe\" loading=\"lazy\" \/><\/p>\n<p>\u6570\u636e\u5e93\u3001Redis\u3001\u7ba1\u7406\u9762\u677f\u8fd9\u7c7b\u670d\u52a1\u4e3a\u4ec0\u4e48\u4e0d\u8be5\u76f4\u63a5\u66b4\u9732\u5728\u516c\u7f51\uff1f\u56e0\u4e3a\u6bcf\u4e00\u6b21\u66b4\u9732\u90fd\u662f\u4e00\u4e2a\u53ef\u88ab\u626b\u63cf\u3001\u53ef\u88ab\u7206\u7834\u7684\u5165\u53e3\u3002\u66f4\u7a33\u59a5\u7684\u505a\u6cd5\u662f\u628a\u5b83\u4eec\u7559\u5728\u5185\u7f51\uff0c\u7528 SSH\uff08Secure Shell\uff0c\u4e00\u79cd\u52a0\u5bc6\u7684\u8fdc\u7a0b\u767b\u5f55\u534f\u8bae\uff09\u7684\u52a0\u5bc6\u901a\u9053\u6309\u9700\u8bbf\u95ee\u3002\u8fd9\u7bc7\u6587\u7ae0\u4f1a\u7528\u4e00\u5957\u53ef\u590d\u5236\u7684\u914d\u7f6e\uff0c\u5e26\u4f60\u8d70\u901a\u672c\u5730\u8f6c\u53d1\u3001\u8fdc\u7a0b\u8f6c\u53d1\u3001\u52a8\u6001\u8f6c\u53d1\u4e0e\u8df3\u677f\u673a\u56db\u4e2a\u573a\u666f\uff0c\u5e2e\u52a9\u4f60\u628a\u5185\u7f51\u670d\u52a1\u7684\u516c\u7f51\u66b4\u9732\u9762\u6536\u7f29\u5230\u53ea\u5269\u4e00\u4e2a SSH \u7aef\u53e3\u3002\u5728\u52a8\u624b\u4e4b\u524d\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5148\u8bfb\u4e00\u8bfb\u8fd9\u7bc7 <a href=\"https:\/\/cn.hostease.com\/blog\/guides\/wordpress-hacked-cleanup-server-hardening\/\">WordPress \u7f51\u7ad9\u88ab\u9ed1\u6e05\u7406\u4e0e\u670d\u52a1\u5668\u52a0\u56fa\u5b9e\u5f55<\/a>\uff0c\u770b\u770b\u771f\u5b9e\u7684\u5165\u4fb5\u6848\u4f8b\u91cc\u5165\u53e3\u9632\u7ebf\u662f\u600e\u4e48\u88ab\u7a81\u7834\u7684\uff0c\u518d\u56de\u6765\u505a\u672c\u7ae0\u7684\u8f6c\u53d1\u5b9e\u9a8c\u4f1a\u66f4\u6709\u65b9\u5411\u611f\u3002<\/p>\n<h2>\u4e00\u3001\u573a\u666f\u51c6\u5907\uff1a\u4e00\u53f0\u6709\u516c\u7f51 IP \u7684\u5165\u53e3\u670d\u52a1\u5668<\/h2>\n<p>\u4e3a\u4e86\u8ba9\u4f60\u53ef\u4ee5\u76f4\u63a5\u7167\u6284\u547d\u4ee4\uff0c\u6211\u4eec\u5148\u7ea6\u5b9a\u4e00\u5957\u8d2f\u7a7f\u5168\u6587\u7684\u793a\u4f8b\u73af\u5883\uff1a\u4e00\u53f0\u5e26\u516c\u7f51 IP \u7684\u5165\u53e3\u670d\u52a1\u5668\uff08\u4e0b\u79f0\u8df3\u677f\u673a\uff09\uff0cIP \u4e3a <code>203.0.113.10<\/code>\uff0cSSH \u7aef\u53e3 <code>22<\/code>\uff1b\u4e24\u53f0\u5185\u7f51\u670d\u52a1\u5668 <code>10.0.0.5<\/code>\uff08\u8dd1 MySQL\uff0c\u76d1\u542c 3306\uff09\u548c <code>10.0.0.6<\/code>\uff08\u8dd1\u7ba1\u7406\u9762\u677f\uff0c\u76d1\u542c 8080\uff09\uff1b\u4f60\u7684\u672c\u5730\u7535\u8111\u901a\u8fc7 SSH \u5bc6\u94a5\u767b\u5f55\u8df3\u677f\u673a\u3002\u4f60\u53ef\u4ee5\u5728 <a href=\"https:\/\/cn.hostease.com\/vps\/\">Hostease \u7684 VPS \u4e3b\u673a<\/a>\uff08<a href=\"https:\/\/cn.hostease.com\/vps\/\">VPS<\/a>\uff0c\u5373<a href=\"https:\/\/cn.hostease.com\/vps\/\">\u865a\u62df\u4e13\u7528\u670d\u52a1\u5668<\/a>\uff0c\u662f\u628a\u4e00\u53f0<a href=\"https:\/\/cn.hostease.com\/dedicated-server\/\">\u7269\u7406\u670d\u52a1\u5668<\/a>\u5212\u5206\u51fa\u7684\u591a\u4e2a\u72ec\u7acb\u8fd0\u884c\u73af\u5883\uff09\u4e0a\u5feb\u901f\u51c6\u5907\u8fd9\u6837\u4e00\u53f0\u5165\u53e3\u673a\uff0c\u9009\u6700\u4f4e\u914d\u7f6e\u5373\u53ef\uff0c\u56e0\u4e3a\u5b83\u53ea\u627f\u8f7d SSH \u8fde\u63a5\uff0c\u51e0\u4e4e\u4e0d\u6d88\u8017 CPU \u4e0e\u5185\u5b58\u3002<\/p>\n<p>\u52a8\u624b\u524d\u5148\u505a\u4e00\u6b21\u57fa\u7ebf\u68c0\u67e5\uff0c\u786e\u8ba4\u670d\u52a1\u786e\u5b9e\u53ea\u5728\u5185\u7f51\u76d1\u542c\u3001\u8df3\u677f\u673a\u53ef\u4ee5\u8fde\u901a\u5b83\u4eec\uff1a<\/p>\n<pre><code class=\"language-bash\">ss -tlnp | grep -E '3306|8080'\nssh root@203.0.113.10 &quot;nc -zv 10.0.0.5 3306&quot;\n<\/code><\/pre>\n<p>\u5982\u679c\u7b2c\u4e00\u6761\u547d\u4ee4\u663e\u793a <code>127.0.0.1:3306<\/code> \u6216\u5185\u7f51\u5730\u5740\uff0c\u8bf4\u660e\u6570\u636e\u5e93\u6ca1\u6709\u66b4\u9732\u516c\u7f51\uff0c\u8fd9\u6b63\u662f\u6211\u4eec\u60f3\u8981\u7684\u72b6\u6001\uff1b\u5982\u679c\u663e\u793a <code>0.0.0.0:3306<\/code>\uff0c\u5e94\u8be5\u5148\u4fee\u6539 <code>my.cnf<\/code> \u4e2d\u7684 <code>bind-address<\/code> \u6216\u7528\u9632\u706b\u5899\u5c01\u6389\u516c\u7f51\u8bbf\u95ee\uff0c\u518d\u505a\u540e\u9762\u7684\u8f6c\u53d1\u914d\u7f6e\u3002\u60f3\u7cfb\u7edf\u5b66\u4e60\u9632\u706b\u5899\u89c4\u5219\uff0c\u53ef\u4ee5\u53c2\u8003\u8fd9\u7bc7 <a href=\"https:\/\/cn.hostease.com\/blog\/guides\/linux-server-cis-benchmark\/\">Linux \u670d\u52a1\u5668\u5b89\u5168\u57fa\u7ebf\u81ea\u67e5<\/a>\uff0c\u628a\u7aef\u53e3\u6700\u5c0f\u5316\u4f5c\u4e3a\u7b2c\u4e00\u6761\u57fa\u7ebf\u6765\u6267\u884c\u3002<\/p>\n<h2>\u4e8c\u3001\u672c\u5730\u8f6c\u53d1\uff1a\u5728\u5bb6\u8bbf\u95ee\u5185\u7f51\u6570\u636e\u5e93<\/h2>\n<p>\u672c\u5730\u8f6c\u53d1\uff08local forwarding\uff09\u89e3\u51b3\u6700\u5e38\u89c1\u7684\u9700\u6c42\uff1a\u4f60\u5728\u672c\u5730\u7535\u8111\u4e0a\u60f3\u7528\u56fe\u5f62\u5de5\u5177\u8fde\u63a5\u5185\u7f51\u91cc\u7684 MySQL\uff0c\u4f46\u6570\u636e\u5e93\u6839\u672c\u6ca1\u6709\u4efb\u4f55\u516c\u7f51\u5730\u5740\u3002\u547d\u4ee4\u662f\uff1a<\/p>\n<pre><code class=\"language-bash\">ssh -N -L 13306:10.0.0.5:3306 root@203.0.113.10\n<\/code><\/pre>\n<p>\u62c6\u5f00\u770b\u8fd9\u6761\u547d\u4ee4\uff1a<code>-L<\/code> \u58f0\u660e\u672c\u5730\u8f6c\u53d1\uff1b<code>13306<\/code> \u662f\u5f00\u5728\u4f60\u672c\u5730\u7535\u8111\u4e0a\u7684\u7aef\u53e3\uff1b<code>10.0.0.5:3306<\/code> \u662f\u76ee\u6807\u670d\u52a1\uff0c\u6ce8\u610f\u5b83\u662f\u4ee5\u8df3\u677f\u673a\u4e3a\u8d77\u70b9\u53bb\u8fde\u63a5\u7684\uff1b<code>-N<\/code> \u8868\u793a\u53ea\u5efa\u7acb\u96a7\u9053\u3001\u4e0d\u6253\u5f00\u8fdc\u7a0b shell\u3002\u6267\u884c\u540e\uff0c\u672c\u5730 <code>13306<\/code> \u7aef\u53e3\u7684\u6d41\u91cf\u4f1a\u7ecf SSH \u52a0\u5bc6\u9001\u5230\u8df3\u677f\u673a\uff0c\u518d\u7531\u8df3\u677f\u673a\u8bbf\u95ee <code>10.0.0.5:3306<\/code>\u3002\u6b64\u65f6\u5728\u4f60\u7684\u6570\u636e\u5e93\u5de5\u5177\u91cc\u8fde\u63a5 <code>127.0.0.1:13306<\/code>\uff0c\u8f93\u5165\u7684\u5374\u662f\u5185\u7f51 MySQL \u7684\u8d26\u53f7\u5bc6\u7801\uff0c\u6548\u679c\u7b49\u540c\u4e8e\u628a\u6570\u636e\u5e93\u201c\u62c9\u201d\u5230\u4e86\u4f60\u9762\u524d\u3002<\/p>\n<p>\u547d\u4ee4\u884c\u9a8c\u8bc1\u8fde\u901a\u6027\u53ef\u4ee5\u7528\uff1a<\/p>\n<pre><code class=\"language-bash\">mysql -h 127.0.0.1 -P 13306 -u dbuser -p\n<\/code><\/pre>\n<p>\u6709\u4e2a\u7ec6\u8282\u5bb9\u6613\u8e29\u5751\uff1a\u8fde\u63a5\u5de5\u5177\u91cc\u5fc5\u987b\u586b <code>127.0.0.1<\/code> \u800c\u4e0d\u662f <code>localhost<\/code>\u3002\u5f88\u591a MySQL \u5ba2\u6237\u7aef\u9047\u5230 <code>localhost<\/code> \u4f1a\u6539\u7528 Unix socket\uff0c\u6839\u672c\u4e0d\u8d70 TCP \u7aef\u53e3\uff0c\u4e8e\u662f\u51fa\u73b0\u201c\u96a7\u9053\u660e\u660e\u901a\u4e86\u5374\u8fde\u4e0d\u4e0a\u201d\u7684\u5047\u6545\u969c\u3002\u53e6\u5916\uff0c\u5982\u679c\u4f60\u5e0c\u671b\u8fd9\u6761\u96a7\u9053\u5728\u540e\u53f0\u5e38\u9a7b\uff0c\u53ef\u4ee5\u52a0\u4e0a <code>-f<\/code> \u53c2\u6570\u8ba9\u5b83\u5efa\u7acb\u540e\u81ea\u52a8\u8f6c\u5165\u540e\u53f0\uff0c\u914d\u5408 <code>ServerAliveInterval<\/code> \u4fdd\u6301\u957f\u8fde\u63a5\uff0c\u5177\u4f53\u5199\u6cd5\u89c1\u7b2c\u4e94\u8282\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<h2>\u4e09\u3001\u8fdc\u7a0b\u8f6c\u53d1\u4e0e\u52a8\u6001\u8f6c\u53d1\uff1a\u4e24\u4e2a\u8865\u5145\u573a\u666f<\/h2>\n<p>\u8fdc\u7a0b\u8f6c\u53d1\uff08remote forwarding\uff09\u7684\u65b9\u5411\u6b63\u597d\u76f8\u53cd\uff1a\u670d\u52a1\u5668\u4e0a\u7684\u670d\u52a1\u9700\u8981\u88ab\u5916\u90e8\u8bbf\u95ee\u3002\u5178\u578b\u4f8b\u5b50\u662f\u5185\u7f51\u7ba1\u7406\u9762\u677f <code>10.0.0.6:8080<\/code> \u9700\u8981\u4e34\u65f6\u7ed9\u540c\u4e8b\u770b\u4e00\u773c\uff0c\u4f60\u4e0d\u60f3\u4e3a\u5b83\u5f00\u516c\u7f51\u7aef\u53e3\uff0c\u4e8e\u662f\u767b\u5f55\u65f6\u6267\u884c\uff1a<\/p>\n<pre><code class=\"language-bash\">ssh -N -R 18080:10.0.0.6:8080 root@203.0.113.10\n<\/code><\/pre>\n<p>\u8fd9\u6761\u547d\u4ee4\u8ba9\u8df3\u677f\u673a\u76d1\u542c <code>18080<\/code>\uff0c\u4efb\u4f55\u4eba\u8bbf\u95ee <code>http:\/\/203.0.113.10:18080<\/code> \u65f6\uff0c\u6d41\u91cf\u4f1a\u53cd\u5411\u7a7f\u8fc7 SSH \u96a7\u9053\u5230\u8fbe\u4f60\u8fd9\u8fb9\uff0c\u518d\u7531\u4f60\u7684\u673a\u5668\u8f6c\u53d1\u5230 <code>10.0.0.6:8080<\/code>\u3002\u5982\u679c\u60f3\u8ba9\u8fd9\u4e2a\u7aef\u53e3\u5bf9\u8df3\u677f\u673a\u4e4b\u5916\u7684\u4eba\u4e5f\u53ef\u8bbf\u95ee\uff0c\u9700\u8981\u5728\u8df3\u677f\u673a\u7684 <code>\/etc\/ssh\/sshd_config<\/code> \u4e2d\u8bbe\u7f6e <code>GatewayPorts yes<\/code> \u5e76\u91cd\u542f sshd\uff0c\u7528\u5b8c\u52a1\u5fc5\u5173\u95ed\uff0c\u907f\u514d\u4e34\u65f6\u901a\u9053\u53d8\u6210\u5e38\u9a7b\u66b4\u9732\u9762\u3002<\/p>\n<p>\u52a8\u6001\u8f6c\u53d1\uff08dynamic forwarding\uff09\u5219\u9002\u5408\u201c\u4e00\u5806\u5185\u7f51\u5730\u5740\u90fd\u60f3\u4e34\u65f6\u8bbf\u95ee\u201d\u7684\u573a\u666f\uff1a<\/p>\n<pre><code class=\"language-bash\">ssh -N -D 1080 root@203.0.113.10\n<\/code><\/pre>\n<p>\u6267\u884c\u540e\u672c\u5730 <code>1080<\/code> \u7aef\u53e3\u53d8\u6210\u4e00\u4e2a SOCKS5 \u4ee3\u7406\uff0c\u6d4f\u89c8\u5668\u6216\u652f\u6301\u4ee3\u7406\u7684\u5de5\u5177\u628a\u6d41\u91cf\u4ea4\u7ed9\u5b83\uff0cSSH \u4f1a\u6309\u76ee\u6807\u5730\u5740\u52a8\u6001\u51b3\u5b9a\u7ecf\u8df3\u677f\u673a\u8f6c\u53d1\u5230\u54ea\u4e2a\u5185\u7f51\u670d\u52a1\u3002\u914d\u5408\u6d4f\u89c8\u5668\u7684\u4ee3\u7406\u63d2\u4ef6\uff08\u5982 SwitchyOmega \u6307\u5411 <code>127.0.0.1:1080<\/code>\uff09\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u7528\u57df\u540d\u8bbf\u95ee\u53ea\u5bf9\u5185\u7f51 DNS\uff08Domain Name System\uff0c\u57df\u540d\u89e3\u6790\u670d\u52a1\uff0c\u8d1f\u8d23\u628a\u57df\u540d\u7ffb\u8bd1\u6210 IP \u5730\u5740\uff09\u751f\u6548\u7684\u7cfb\u7edf\uff0c\u4e0d\u7528\u4e3a\u6bcf\u4e2a\u670d\u52a1\u5355\u72ec\u5efa\u96a7\u9053\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/09\/ssh-port-forwarding-types-comparison.webp\" alt=\"\u4e09\u79cd SSH \u7aef\u53e3\u8f6c\u53d1\u65b9\u5411\u5bf9\u6bd4\u793a\u610f\u56fe\" loading=\"lazy\" \/><\/p>\n<h2>\u56db\u3001\u8df3\u677f\u673a\uff1a\u591a\u53f0\u5185\u7f51\u670d\u52a1\u5668\u7684\u7edf\u4e00\u5165\u53e3<\/h2>\n<p>\u5f53\u5185\u7f51\u673a\u5668\u4e0d\u6b62\u4e00\u4e24\u53f0\u65f6\uff0c\u9010\u53f0\u914d\u7f6e\u8f6c\u53d1\u4e0d\u5982\u76f4\u63a5\u628a <code>203.0.113.10<\/code> \u5f53\u4f5c\u8df3\u677f\u673a\uff08jump host\uff09\uff0c\u4e00\u6b21\u767b\u5f55\u76f4\u8fbe\u4efb\u610f\u5185\u7f51\u4e3b\u673a\u3002\u539f\u751f\u547d\u4ee4\u662f <code>ssh -J<\/code>\uff1a<\/p>\n<pre><code class=\"language-bash\">ssh -J root@203.0.113.10 root@10.0.0.5\n<\/code><\/pre>\n<p>\u8fd9\u6761\u547d\u4ee4\u4f1a\u5148\u8fde\u8df3\u677f\u673a\uff0c\u518d\u7531\u5b83\u8f6c\u53d1\u5230 <code>10.0.0.5<\/code>\uff0c\u5168\u7a0b\u4e00\u6761\u52a0\u5bc6\u94fe\u8def\u3002\u66f4\u4f18\u96c5\u7684\u505a\u6cd5\u662f\u628a\u62d3\u6251\u5199\u8fdb <code>~\/.ssh\/config<\/code>\uff0c\u4e4b\u540e\u4f60\u53ea\u9700\u8981\u6572 <code>ssh db<\/code>\uff1a<\/p>\n<pre><code class=\"language-text\">Host jump\n    HostName 203.0.113.10\n    User root\n    IdentityFile ~\/.ssh\/id_ed25519\n\nHost db\n    HostName 10.0.0.5\n    User root\n    ProxyJump jump\n\nHost panel\n    HostName 10.0.0.6\n    User root\n    ProxyJump jump\n<\/code><\/pre>\n<p>\u8df3\u677f\u673a\u81ea\u8eab\u7684\u52a0\u56fa\u540c\u6837\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u73b0\u5728\u662f\u6574\u4e2a\u5185\u7f51\u552f\u4e00\u7684\u516c\u7f51\u5165\u53e3\u3002\u63a8\u8350\u4e09\u6b65\u8d70\uff1a\u7b2c\u4e00\uff0c\u7981\u7528\u5bc6\u7801\u767b\u5f55\uff0c<code>sshd_config<\/code> \u4e2d\u8bbe\u7f6e <code>PasswordAuthentication no<\/code>\uff0c\u53ea\u5141\u8bb8\u5bc6\u94a5\uff1b\u7b2c\u4e8c\uff0c\u628a <code>AllowTcpForwarding<\/code> \u4fdd\u6301\u4e3a <code>yes<\/code>\uff08\u5426\u5219\u8f6c\u53d1\u5931\u6548\uff09\uff0c\u4f46\u7528 <code>AllowUsers<\/code> \u9650\u5b9a\u53ef\u767b\u5f55\u8d26\u53f7\uff1b\u7b2c\u4e09\uff0c\u5728\u9632\u706b\u5899\u5c42\u9762\u53ea\u653e\u884c SSH \u7aef\u53e3\uff0c\u5e76\u7528 <code>fail2ban<\/code> \u81ea\u52a8\u5c01\u7981\u7206\u7834 IP\u3002\u8fd9\u5957\u5165\u53e3\u52a0\u56fa\u4e0e <a href=\"https:\/\/cn.hostease.com\/blog\/guides\/ansible-vps-batch-init-server\/\">Ansible \u6279\u91cf\u521d\u59cb\u5316\u670d\u52a1\u5668<\/a> \u7684\u6d41\u7a0b\u53ef\u4ee5\u7ec4\u5408\u4f7f\u7528\uff1a\u65b0\u673a\u5668\u4e0a\u67b6\u65f6\u5148\u7531 Ansible \u7edf\u4e00\u90e8\u7f72\u5bc6\u94a5\u4e0e\u57fa\u7ebf\u914d\u7f6e\uff0c\u518d\u7eb3\u5165\u8df3\u677f\u673a\u7ba1\u7406\uff0c\u5165\u53e3\u7b56\u7565\u5c31\u4e0d\u4f1a\u56e0\u4e3a\u673a\u5668\u53d8\u591a\u800c\u5931\u63a7\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/09\/ssh-jump-host-architecture.webp\" alt=\"\u8df3\u677f\u673a\u7edf\u4e00\u5165\u53e3\u8fde\u63a5\u591a\u53f0\u5185\u7f51\u670d\u52a1\u5668\u7684\u793a\u610f\u56fe\" loading=\"lazy\" \/><\/p>\n<h2>\u4e94\u3001\u8ba9\u96a7\u9053\u66f4\u7a33\uff1a\u5e38\u7528\u53c2\u6570\u4e0e\u6392\u969c<\/h2>\n<p>\u4e34\u65f6\u6572\u547d\u4ee4\u5efa\u7acb\u7684\u96a7\u9053\u4e00\u65e6\u65ad\u7ebf\u5c31\u6d88\u5931\u4e86\uff0c\u65e5\u5e38\u4f7f\u7528\u5efa\u8bae\u628a\u53c2\u6570\u56fa\u5316\u5230 <code>~\/.ssh\/config<\/code>\uff1a<\/p>\n<pre><code class=\"language-text\">Host tunnel-db\n    HostName 203.0.113.10\n    User root\n    LocalForward 13306 10.0.0.5:3306\n    ServerAliveInterval 30\n    ServerAliveCountMax 3\n    ExitOnForwardFailure yes\n<\/code><\/pre>\n<p>\u56db\u4e2a\u53c2\u6570\u5404\u53f8\u5176\u804c\uff1a<code>ServerAliveInterval 30<\/code> \u6bcf 30 \u79d2\u53d1\u4e00\u6b21\u5fc3\u8df3\uff0c\u9632\u6b62\u4e2d\u95f4\u8bbe\u5907\u6390\u6389\u7a7a\u95f2\u8fde\u63a5\uff1b<code>ServerAliveCountMax 3<\/code> \u8868\u793a\u8fde\u7eed 3 \u6b21\u5fc3\u8df3\u65e0\u54cd\u5e94\u5373\u5224\u5b9a\u65ad\u7ebf\u9000\u51fa\uff0c\u907f\u514d\u534a\u6b7b\u8fde\u63a5\u5360\u7740\u7aef\u53e3\uff1b<code>ExitOnForwardFailure yes<\/code> \u5219\u4fdd\u8bc1\u7aef\u53e3\u88ab\u5360\u7528\u3001\u8f6c\u53d1\u5efa\u7acb\u5931\u8d25\u65f6\u76f4\u63a5\u9000\u51fa\uff0c\u4f60\u80fd\u5728\u7b2c\u4e00\u65f6\u95f4\u53d1\u73b0\u800c\u4e0d\u662f\u7b49\u5230\u8fde\u63a5\u6570\u636e\u5e93\u65f6\u624d\u62a5\u9519\u3002\u4e4b\u540e\u6267\u884c <code>ssh -N tunnel-db<\/code> \u5373\u53ef\u5f97\u5230\u4e00\u6761\u53ef\u89c2\u6d4b\u7684\u957f\u96a7\u9053\uff1b\u82e5\u8981\u5f00\u673a\u81ea\u52a8\u91cd\u8fde\uff0c\u53ef\u4ee5\u7528 <code>autossh -M 0 -N tunnel-db<\/code> \u4ea4\u7ed9 systemd \u6216 cron \u6258\u7ba1\u3002<\/p>\n<p>\u6392\u969c\u65f6\u6309\u94fe\u8def\u987a\u5e8f\u68c0\u67e5\u4e09\u5904\u5373\u53ef\u5b9a\u4f4d\u7edd\u5927\u591a\u6570\u95ee\u9898\u3002\u7b2c\u4e00\u5904\u770b\u672c\u5730\uff1a<code>ss -tlnp | grep 13306<\/code> \u786e\u8ba4\u672c\u5730\u7aef\u53e3\u5df2\u5728\u76d1\u542c\uff1b\u7b2c\u4e8c\u5904\u770b\u8df3\u677f\u673a\uff1a<code>ssh root@203.0.113.10 \"nc -zv 10.0.0.5 3306\"<\/code> \u786e\u8ba4\u8df3\u677f\u673a\u5230\u76ee\u6807\u670d\u52a1\u53ef\u8fbe\uff1b\u7b2c\u4e09\u5904\u52a0 <code>-v<\/code> \u53c2\u6570\u91cd\u8fde\uff1a<code>ssh -v -N -L 13306:10.0.0.5:3306 root@203.0.113.10<\/code>\uff0c\u4ece verbose \u8f93\u51fa\u91cc\u627e <code>channel : open failed<\/code> \u6216 <code>administratively prohibited<\/code> \u5b57\u6837\u2014\u2014\u540e\u8005\u901a\u5e38\u610f\u5473\u7740\u8df3\u677f\u673a\u7684 <code>AllowTcpForwarding<\/code> \u88ab\u8bbe\u6210\u4e86 <code>no<\/code>\uff0c\u6539\u56de <code>yes<\/code> \u5e76\u91cd\u542f sshd \u5373\u53ef\u3002<\/p>\n<h2>\u516d\u3001\u603b\u7ed3\u4e0e\u884c\u52a8\u5efa\u8bae<\/h2>\n<p>\u56de\u987e\u5168\u6587\u7684\u914d\u7f6e\u601d\u8def\uff1a\u5185\u7f51\u670d\u52a1\u4e00\u5f8b\u4e0d\u66b4\u9732\u516c\u7f51\uff0c\u6570\u636e\u5e93\u7528\u672c\u5730\u8f6c\u53d1\u6309\u9700\u8bbf\u95ee\uff0c\u4e34\u65f6\u6f14\u793a\u7528\u8fdc\u7a0b\u8f6c\u53d1\u4e14\u7528\u5b8c\u5373\u5173\uff0c\u6279\u91cf\u6d4f\u89c8\u7528\u52a8\u6001\u8f6c\u53d1\uff0c\u591a\u673a\u7ba1\u7406\u4ea4\u7ed9 <code>ProxyJump<\/code> \u8df3\u677f\u673a\u3002\u8fd9\u5957\u7ec4\u5408\u7684\u5173\u952e\u5728\u4e8e\u6536\u655b\u2014\u2014\u6240\u6709\u8bbf\u95ee\u90fd\u6c47\u805a\u5230\u4e00\u4e2a SSH \u7aef\u53e3\u4e0a\uff0c\u5b89\u5168\u8fb9\u754c\u6e05\u6670\uff0c\u5ba1\u8ba1\u4e5f\u53ea\u9700\u76ef\u4f4f\u4e00\u53f0\u673a\u5668\u7684 <code>\/var\/log\/auth.log<\/code>\u3002<\/p>\n<p>\u5982\u679c\u4f60\u51c6\u5907\u52a8\u624b\u843d\u5730\uff0c\u5efa\u8bae\u6309\u8fd9\u4e2a\u987a\u5e8f\u63a8\u8fdb\uff1a<\/p>\n<ul>\n<li>\u5148\u7ed9\u5165\u53e3\u673a\u914d\u597d\u5bc6\u94a5\u767b\u5f55\u5e76\u7981\u7528\u5bc6\u7801\uff0c\u8fd9\u662f\u6240\u6709\u540e\u7eed\u64cd\u4f5c\u7684\u5730\u57fa<\/li>\n<li>\u518d\u9a8c\u8bc1\u4e00\u6761\u672c\u5730\u8f6c\u53d1\u5230\u6570\u636e\u5e93\u7684\u96a7\u9053\uff0c\u8dd1\u901a\u6700\u5c0f\u95ed\u73af<\/li>\n<li>\u7136\u540e\u628a\u5185\u7f51\u673a\u5668\u5168\u90e8\u5199\u5165 <code>~\/.ssh\/config<\/code> \u7684 <code>ProxyJump<\/code> \u62d3\u6251<\/li>\n<li>\u6700\u540e\u7528 <code>autossh<\/code> \u6216 systemd \u56fa\u5316\u5e38\u7528\u96a7\u9053\uff0c\u5e76\u7528 <a href=\"https:\/\/cn.hostease.com\/blog\/guides\/linux-rsync-crontab\/\">rsync \u4e0e crontab \u5f02\u5730\u5907\u4efd<\/a> \u7ed9\u8df3\u677f\u673a\u81ea\u8eab\u7684\u914d\u7f6e\u6587\u4ef6\u505a\u5b9a\u671f\u5907\u4efd<\/li>\n<\/ul>\n<p>\u5165\u53e3\u673a\u7684\u9009\u62e9\u4e0a\uff0c\u4e00\u53f0\u4f4e\u914d\u4f46\u7f51\u7edc\u8d28\u91cf\u7a33\u5b9a\u7684 <a href=\"https:\/\/cn.hostease.com\/vps\/\">Hostease VPS<\/a> \u5c31\u8db3\u591f\u627f\u62c5\u8df3\u677f\u673a\u89d2\u8272\uff1b\u5982\u679c\u5185\u7f51\u89c4\u6a21\u8f83\u5927\u3001\u9700\u8981\u66f4\u9ad8\u5e76\u53d1\u7684\u8f6c\u53d1\u541e\u5410\uff0c\u518d\u8003\u8651<a href=\"https:\/\/cn.hostease.com\/dedicated-server\/\">\u72ec\u7acb\u670d\u52a1\u5668<\/a>\u3002\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u5efa\u8bae\u6bcf\u5b63\u5ea6\u590d\u67e5\u4e00\u6b21 <code>sshd_config<\/code> \u4e0e\u9632\u706b\u5899\u89c4\u5219\uff0c\u786e\u8ba4\u6ca1\u6709\u591a\u4f59\u7684\u7aef\u53e3\u6084\u6084\u6253\u5f00\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/09\/ssh-secure-access-checklist.webp\" alt=\"SSH \u5b89\u5168\u8bbf\u95ee\u5185\u7f51\u670d\u52a1\u7684\u5b8c\u6574\u914d\u7f6e\u6d41\u7a0b\u6e05\u5355\u56fe\" loading=\"lazy\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8be6\u89e3 SSH \u672c\u5730\u8f6c\u53d1\u3001\u8fdc\u7a0b\u8f6c\u53d1\u3001\u52a8\u6001\u8f6c\u53d1\u4e0e\u8df3\u677f\u673a\u914d\u7f6e\uff0c\u5e2e\u52a9\u4f60\u5b89\u5168\u8bbf\u95ee\u5185\u7f51\u6570\u636e\u5e93\u3001\u7ba1\u7406\u9762\u677f\u4e0e\u591a\u53f0\u5185\u7f51\u670d\u52a1\u5668\uff0c\u9644\u9632\u706b\u5899\u4e0e\u5bc6\u94a5\u52a0\u56fa\u6e05\u5355\u3002<\/p>\n","protected":false},"author":2,"featured_media":33260,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4099],"tags":[373,4778,157,5109,608],"class_list":["post-33264","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-ssh","tag-4778","tag-157","tag-5109","tag-608"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/09\/ssh-port-forwarding-jump-host-cover.webp","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/33264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/comments?post=33264"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/33264\/revisions"}],"predecessor-version":[{"id":33265,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/33264\/revisions\/33265"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/media\/33260"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/media?parent=33264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/categories?post=33264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/tags?post=33264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}