{"id":326,"date":"2025-07-25T11:49:55","date_gmt":"2025-07-25T03:49:55","guid":{"rendered":"https:\/\/qkd.koudaipc.com\/?p=326"},"modified":"2026-01-27T07:48:43","modified_gmt":"2026-01-26T23:48:43","slug":"termux%e9%85%8d%e7%bd%aessh%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/qkd.koudaipc.com\/en\/2025\/07\/25\/termux%e9%85%8d%e7%bd%aessh%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%95%99%e7%a8%8b\/","title":{"rendered":"Termux\u914d\u7f6eSSH\u670d\u52a1\u5668\u6559\u7a0b"},"content":{"rendered":"<p>\u5728 Termux \u4e2d\u914d\u7f6e SSH \u670d\u52a1\u5668\u5141\u8bb8\u4f60\u901a\u8fc7 SSH \u8fdc\u7a0b\u8bbf\u95ee Android \u8bbe\u5907\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<hr \/>\n<h3><strong>1. \u5b89\u88c5 OpenSSH<\/strong><\/h3>\n<pre><code class=\"language-bash\">pkg update\npkg upgrade\npkg install openssh<\/code><\/pre>\n<hr \/>\n<h3><strong>2. \u8bbe\u7f6e\u767b\u5f55\u5bc6\u7801<\/strong><\/h3>\n<p>Termux \u9ed8\u8ba4\u7981\u7528\u7a7a\u5bc6\u7801\u767b\u5f55\uff0c\u9700\u8bbe\u7f6e\u7528\u6237\u5bc6\u7801\uff1a<\/p>\n<pre><code class=\"language-bash\">passwd<\/code><\/pre>\n<blockquote>\n<p>\u8f93\u5165\u5e76\u786e\u8ba4\u4f60\u7684\u5bc6\u7801\uff08\u8f93\u5165\u65f6\u4e0d\u53ef\u89c1\uff09\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h3><strong>3. \u542f\u52a8 SSH \u670d\u52a1<\/strong><\/h3>\n<pre><code class=\"language-bash\">sshd<\/code><\/pre>\n<hr \/>\n<h3><strong>4. \u83b7\u53d6\u8bbe\u5907 IP \u5730\u5740<\/strong><\/h3>\n<pre><code class=\"language-bash\">ifconfig<\/code><\/pre>\n<p>\u6216<\/p>\n<pre><code class=\"language-bash\">ip addr show<\/code><\/pre>\n<blockquote>\n<p>\u627e\u5230 &lt;code&gt;wlan0&lt;\/code&gt;\uff08Wi-Fi\uff09\u6216 &lt;code&gt;rmnet_data0&lt;\/code&gt;\uff08\u79fb\u52a8\u6570\u636e\uff09\u7684 IP \u5730\u5740\uff08\u5982 &lt;code&gt;192.168.x.x&lt;\/code&gt;\uff09\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h3><strong>5. \u8fde\u63a5 Termux<\/strong><\/h3>\n<p>\u5728\u53e6\u4e00\u53f0\u8bbe\u5907\u7684\u7ec8\u7aef\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"language-bash\">ssh -p 8022 &amp;lt;IP\u5730\u5740&amp;gt;<\/code><\/pre>\n<blockquote>\n<p>\u793a\u4f8b\uff1a&lt;code&gt;ssh -p 8022 192.168.1.100&lt;\/code&gt;<br \/>\n\u8f93\u5165\u6b65\u9aa4 2 \u8bbe\u7f6e\u7684\u5bc6\u7801\u767b\u5f55\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h3><strong>6. \u81ea\u52a8\u542f\u52a8 SSH\uff08\u53ef\u9009\uff09<\/strong><\/h3>\n<p>\u5728 &lt;code&gt;~\/.bashrc&lt;\/code&gt; \u4e2d\u6dfb\u52a0\u5f00\u673a\u81ea\u542f\uff1a<\/p>\n<pre><code class=\"language-bash\">echo &amp;quot;sshd&amp;quot; &amp;gt;&amp;gt; ~\/.bashrc<\/code><\/pre>\n<blockquote>\n<p>\u6bcf\u6b21\u6253\u5f00 Termux \u4f1a\u81ea\u52a8\u542f\u52a8 SSH\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h3><strong>7. \u5bc6\u94a5\u767b\u5f55\uff08\u66f4\u5b89\u5168\uff09<\/strong><\/h3>\n<h4><strong>\u751f\u6210\u5bc6\u94a5\u5bf9<\/strong>\uff08\u5728\u5ba2\u6237\u7aef\u64cd\u4f5c\uff09\uff1a<\/h4>\n<pre><code class=\"language-bash\">ssh-keygen -t ed25519<\/code><\/pre>\n<blockquote>\n<p>\u5bc6\u94a5\u9ed8\u8ba4\u4fdd\u5b58\u5728 &lt;code&gt;~\/.ssh\/id_ed25519&lt;\/code&gt;\u3002<\/p>\n<\/blockquote>\n<h4><strong>\u5c06\u516c\u94a5\u590d\u5236\u5230 Termux<\/strong>\uff1a<\/h4>\n<pre><code class=\"language-bash\">ssh-copy-id -p 8022 -i ~\/.ssh\/id_ed25519.pub &amp;lt;IP\u5730\u5740&amp;gt;<\/code><\/pre>\n<p>\u6216\u624b\u52a8\u590d\u5236\uff1a<\/p>\n<pre><code class=\"language-bash\"># \u5728\u5ba2\u6237\u7aef\u67e5\u770b\u516c\u94a5\ncat ~\/.ssh\/id_ed25519.pub\n\n# \u5728 Termux \u4e2d\u7c98\u8d34\u516c\u94a5\u5230\u6587\u4ef6\nmkdir -p ~\/.ssh\nnano ~\/.ssh\/authorized_keys  # \u7c98\u8d34\u5e76\u4fdd\u5b58\nchmod 600 ~\/.ssh\/authorized_keys<\/code><\/pre>\n<h4><strong>\u7981\u7528\u5bc6\u7801\u767b\u5f55\uff08\u53ef\u9009\uff09<\/strong>\uff1a<\/h4>\n<p>\u7f16\u8f91 Termux \u7684 SSH \u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-bash\">nano $PREFIX\/etc\/ssh\/sshd_config<\/code><\/pre>\n<p>\u4fee\u6539\uff1a<\/p>\n<pre><code class=\"language-conf\">PasswordAuthentication no\nChallengeResponseAuthentication no<\/code><\/pre>\n<p>\u91cd\u542f SSH\uff1a<\/p>\n<pre><code class=\"language-bash\">pkill sshd &amp;amp;&amp;amp; sshd<\/code><\/pre>\n<hr \/>\n<h3><strong>\u5e38\u89c1\u95ee\u9898\u89e3\u51b3<\/strong><\/h3>\n<ul>\n<li><strong>\u8fde\u63a5\u88ab\u62d2\u7edd<\/strong>\uff1a\u786e\u4fdd &lt;code&gt;sshd&lt;\/code&gt; \u6b63\u5728\u8fd0\u884c\uff08&lt;code&gt;pgrep sshd&lt;\/code&gt; \u68c0\u67e5\u8fdb\u7a0b\uff09\u3002<\/li>\n<li><strong>\u7aef\u53e3\u51b2\u7a81<\/strong>\uff1a\u4fee\u6539\u7aef\u53e3\uff08\u7f16\u8f91 &lt;code&gt;sshd_config&lt;\/code&gt; \u4e2d\u7684 &lt;code&gt;Port 8022&lt;\/code&gt;\uff09\u3002<\/li>\n<li><strong>\u9632\u706b\u5899\u9650\u5236<\/strong>\uff1a\u5728\u8def\u7531\u5668\/\u624b\u673a\u9632\u706b\u5899\u653e\u884c <strong>8022 \u7aef\u53e3<\/strong>\u3002<\/li>\n<li><strong>\u52a8\u6001 IP \u53d8\u5316<\/strong>\uff1a\u4f7f\u7528\u5de5\u5177\u5982 &lt;code&gt;ngrok&lt;\/code&gt; \u6216 &lt;code&gt;cloudflare tunnel&lt;\/code&gt; \u83b7\u53d6\u56fa\u5b9a\u5730\u5740\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3><strong>\u603b\u7ed3<\/strong><\/h3>\n<pre><code class=\"language-mermaid\">graph LR\nA[\u5b89\u88c5 openssh] --&amp;gt; B[\u8bbe\u7f6e\u5bc6\u7801]\nB --&amp;gt; C[\u542f\u52a8 sshd]\nC --&amp;gt; D[\u83b7\u53d6 IP]\nD --&amp;gt; E[\u8fdc\u7a0b\u8fde\u63a5]\nE --&amp;gt; F[\u5bc6\u94a5\u767b\u5f55\u4f18\u5316]<\/code><\/pre>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u5df2\u6210\u529f\u5728 Termux \u90e8\u7f72 SSH \u670d\u52a1\u5668\uff0c\u53ef\u5b89\u5168\u8fdc\u7a0b\u7ba1\u7406 Android \u8bbe\u5907\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Termux \u4e2d\u914d\u7f6e SSH \u670d\u52a1\u5668\u5141\u8bb8\u4f60\u901a\u8fc7 SSH \u8fdc\u7a0b\u8bbf\u95ee Android \u8bbe\u5907\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u6b65\u9aa4\uff1a  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pmpro_default_level":"","footnotes":""},"categories":[22],"tags":[],"class_list":["post-326","post","type-post","status-publish","format-standard","hentry","category-22","pmpro-has-access"],"_links":{"self":[{"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/posts\/326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/comments?post=326"}],"version-history":[{"count":2,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/posts\/326\/revisions"}],"predecessor-version":[{"id":405,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/posts\/326\/revisions\/405"}],"wp:attachment":[{"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/media?parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/categories?post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qkd.koudaipc.com\/en\/wp-json\/wp\/v2\/tags?post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}