PageSourceSearch

https://www.hestudio.net/assets/how-to-open-sshserver-on-termux.html-5_B34K74.js

js hestudio.net collected 2026-09-24 10:36:33 UTC 8,617 bytes, 8 lines download raw bytes

1import{_ as s,c as t,f as i,o as n}from"./app-D7CCjthX.js";const a={};function r(d,e){return n(),t("div",null,[...e[0]||(e[0]=[i(`<p>众所周知,Termux 是一个 Android 终端仿真应用程序,用于在 Android 手机上搭建一个完整的 Linux 环境。 Termux 不是真实的 Linux 环境,但是 Termux 可以安装真实的 Linux,而且不会损失性能!. 关键是还不需要 root!</p><p>然而,在手机上敲代码总是有一些别扭,所以这篇文章就教你怎么远程链接,也就是用 ssh 连接。</p><h3 id="在-termux-上安装-openssh-服务" tabindex="-1"><a class="header-anchor" href="#在-termux-上安装-openssh-服务"><span>在 Termux 上安装 openssh 服务</span></a></h3><h4 id="安装" tabindex="-1"><a class="header-anchor" href="#安装"><span>安装</span></a></h4><ol><li>打开 Termux</li><li>安装 openssh</li></ol><div class="language-text line-numbers-mode" data-highlighter="prismjs" data-ext="text"><pre><code class="language-text"><span class="line">pkg install openssh -y</span>
2<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><figure><img src="https://img.hestudio.net/img/2023/03/24/641d5f31417e3.jpeg" alt="安装openssh" tabindex="0" loading="lazy"><figcaption>安装openssh</figcaption></figure><ol start="3"><li>安装好之后,我们需要手动启动 sshd</li></ol><div class="language-text line-numbers-mode" data-highlighter="prismjs" data-ext="text"><pre><code class="language-text"><span class="line">sshd</span>
3<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><ol start="4"><li>需要指出的是, sshd 监听的是 8022 端口而不是 22 号端口,因此可以使用下面命令来验证 ssh 服务是否开启</li></ol><div class="language-text line-numbers-mode" data-highlighter="prismjs" data-ext="text"><pre><code class="language-text"><span class="line">ssh localhost -p 8022</span>
4<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><figure><img src="https://img.hestudio.net/img/2023/03/24/641d5f795756f.jpeg" alt="验证是否开启ssh" tabindex="0" loading="lazy"><figcaption>验证是否开启ssh</figcaption></figure><p>如果出现图片上的画面,则已经开启 ssh 服务</p><h4 id="添加-public-key" tabindex="-1"><a class="header-anchor" href="#添加-public-key"><span>添加 Public key</span></a></h4><p>Termux 的 sshd 只能通过密钥登陆,因此你需要在客户端上生成密钥对。</p><div class="language-text line-numbers-mode" data-highlighter="prismjs" data-ext="text"><pre><code class="language-text"><span class="line">ssh-keygen</span>
5<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><figure><img src="https://img.hestudio.net/img/2023/03/24/641d5fb122600.png" alt="生成密钥对" tabindex="0" loading="lazy"><figcaption>生成密钥对</figcaption></figure><p>把客户端上的公钥加到 Termux 中的 .ssh/authorized_keys,这一步比较麻烦。因为你无法使用 ssh-copy-id,只能先把 id_rsa.pub 拷贝到手机上,再在手机上打开该文件,拷贝文件内容后在 Termux 中用 vi 打开 authorized_keys,并复制内容进去。</p><p>或者在电脑上将 id_rsa.pub 文件(是整个文件,不是复制文件内容)拖到文件传输助手中,在手机上用 Termux 打开,点击 EDIT ,然后打开 termux</p><div class="language-text line-numbers-mode" data-highlighter="prismjs" data-ext="text"><pre><code class="language-text"><span class="line">cat ~/downloads/id_rsa.pub &gt;&gt; ~/.ssh/authorized_keys</span>
6<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><p>不过如果客户端上本身也开启了 ssh 服务的话,则会简单很多,可以在 Termux 上执行</p><div class="language-text line-numbers-mode" data-highlighter="prismjs" data-ext="text"><pre><code class="language-text"><span class="line">ssh user@clinet &quot;cat ~/.ssh/id_rsa.pub&quot; &gt;&gt; ~/.ssh/authorized_keys</span>
7<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><p>就行了,其中 clinet 为客户端的地址,user 为登陆用户.</p><h4 id="客户端登陆" tabindex="-1"><a class="header-anchor" href="#客户端登陆"><span>客户端登陆</span></a></h4><p>在客户端上执行</p><div class="language-text line-numbers-mode" data-highlighter="prismjs" data-ext="text"><pre><code class="language-text"><span class="line">ssh 127.0.0.1 -p 8022</span>
8<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><p>把 127.0.0.1 换成手机 ip 手机 IP 可以在 设置 --&gt; WLAN --&gt; 高级设置 里查看 <img src="https://img.hestudio.net/img/2023/03/24/641d5ff99ba32.png" alt="连接ssh" loading="lazy"></p><blockquote><p>最后一次更新:2022.11.1</p></blockquote>`,28)])])}const o=s(a,[["render",r]]),p=JSON.parse('{"path":"/posts/how-to-open-sshserver-on-termux.html","title":"如何在termux中启用ssh server","lang":"zh-CN","frontmatter":{"title":"如何在termux中启用ssh server","tag":["Termux","Linux"],"category":["Android"],"description":"众所周知,Termux 是一个 Android 终端仿真应用程序,用于在 Android 手机上搭建一个完整的 Linux 环境。 Termux 不是真实的 Linux 环境,但是 Termux 可以安装真实的 Linux,而且不会损失性能!. 关键是还不需要 root! 然而,在手机上敲代码总是有一些别扭,所以这篇文章就教你怎么远程链接,也就是用 s...","head":[["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"如何在termux中启用ssh server\\",\\"image\\":[\\"https://img.hestudio.net/img/2023/03/24/641d5f31417e3.jpeg\\",\\"https://img.hestudio.net/img/2023/03/24/641d5f795756f.jpeg\\",\\"https://img.hestudio.net/img/2023/03/24/641d5fb122600.png\\",\\"https://img.hestudio.net/img/2023/03/24/641d5ff99ba32.png\\"],\\"dateModified\\":\\"2025-03-13T06:15:20.000Z\\",\\"author\\":[{\\"@type\\":\\"Person\\",\\"name\\":\\"undefined\\",\\"url\\":\\"https://www.hestudio.net/about/\\",\\"email\\":\\"[email protected]\\"}]}"],["meta",{"property":"og:url","content":"https://www.hestudio.net/posts/how-to-open-sshserver-on-termux.html"}],["meta",{"property":"og:site_name","content":"heStudio"}],["meta",{"property":"og:title","content":"如何在termux中启用ssh server"}],["meta",{"property":"og:description","content":"众所周知,Termux 是一个 Android 终端仿真应用程序,用于在 Android 手机上搭建一个完整的 Linux 环境。 Termux 不是真实的 Linux 环境,但是 Termux 可以安装真实的 Linux,而且不会损失性能!. 关键是还不需要 root! 然而,在手机上敲代码总是有一些别扭,所以这篇文章就教你怎么远程链接,也就是用 s..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:image","content":"https://img.hestudio.net/img/2023/03/24/641d5f31417e3.jpeg"}],["meta",{"property":"og:locale","content":"zh-CN"}
8],["meta",{"property":"og:updated_time","content":"2025-03-13T06:15:20.000Z"}],["meta",{"property":"article:tag","content":"Linux"}],["meta",{"property":"article:tag","content":"Termux"}],["meta",{"property":"article:modified_time","content":"2025-03-13T06:15:20.000Z"}]]},"git":{"createdTime":1671603014000,"updatedTime":1741846520000},"readingTime":{"minutes":1.71,"words":513},"filePathRelative":"posts/how-to-open-sshserver-on-termux.md","excerpt":"<p>众所周知,Termux 是一个 Android 终端仿真应用程序,用于在 Android 手机上搭建一个完整的 Linux 环境。 Termux 不是真实的 Linux 环境,但是 Termux 可以安装真实的 Linux,而且不会损失性能!. 关键是还不需要 root!</p>\\n<p>然而,在手机上敲代码总是有一些别扭,所以这篇文章就教你怎么远程链接,也就是用 ssh 连接。</p>\\n","autoDesc":true}');export{o as comp,p as data};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.