<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>OpenSSH on Ivon's Blog</title><link>https://ivonblog.com/en-us/tags/openssh/</link><description>Recent content in OpenSSH on Ivon's Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>infoivonblog.nkfjt@aleeas.com (Ivon Huang)</managingEditor><webMaster>infoivonblog.nkfjt@aleeas.com (Ivon Huang)</webMaster><copyright>You are welcome to share articles of Ivon's Blog (ivonblog.com). Please include the original URL when citing articles, and abide by CC BY-NC-ND 4.0 license. For commercial use, please write an e-mail to me.</copyright><lastBuildDate>Mon, 21 Nov 2022 16:50:46 +0800</lastBuildDate><atom:link href="https://ivonblog.com/en-us/tags/openssh/index.xml" rel="self" type="application/rss+xml"/><item><title>Turn your phone into an SSH server with Termux, connect to a computer over SSH, and share files</title><link>https://ivonblog.com/en-us/posts/termux-openssh/</link><pubDate>Mon, 21 Nov 2022 16:50:46 +0800</pubDate><author>infoivonblog.nkfjt@aleeas.com (Ivon Huang)</author><guid>https://ivonblog.com/en-us/posts/termux-openssh/</guid><description>&lt;!-- Co-translated by ChatGPT --&gt;
&lt;p&gt;This article introduces how to install OpenSSH with Termux on an Android phone, and log in to your own computer or a remote host via SSH.&lt;/p&gt;
&lt;p&gt;Termux can also run an SSH server on the phone, then let you log in to the phone through an SSH client on a computer. This can be used to transfer files, achieve SMB-like file sharing, or automatically synchronize files between two devices with Rsync.&lt;/p&gt;
&lt;p&gt;The benefit of these tools is that their ports are shared with SSH, and SSH encrypted communication can improve transfer security.&lt;/p&gt;
&lt;p&gt;Incidentally, &lt;a href="https://ivonblog.com/posts/how-to-use-kde-connect/" target="_blank" rel="noreferrer"&gt;KDE Connect&lt;/a&gt;, which connects phones and computers, also uses SSH. If you do not like typing commands, you can try the KDE Connect app first.&lt;/p&gt;

&lt;h2 class="relative group"&gt;1. Install OpenSSH
 &lt;div id="1-install-openssh" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#1-install-openssh" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;

&lt;h3 class="relative group"&gt;1.1. Phone side
 &lt;div id="11-phone-side" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#11-phone-side" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;Please read first: &lt;a href="https://ivonblog.com/en-us/posts/how-to-use-termux/" target="_blank" rel="noreferrer"&gt;How to Use Termux&lt;/a&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Install OpenSSH in Termux, including client and server:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pkg install openssh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="2"&gt;
&lt;li&gt;Termux&amp;rsquo;s virtual user account is always &lt;code&gt;user&lt;/code&gt;. Enter this command, type a password of 4 or more digits, and press Enter:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;passwd&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="3"&gt;
&lt;li&gt;Then run this command in Termux to start the SSH server.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sshd&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="4"&gt;
&lt;li&gt;Since SSHD closes after you exit Termux, you can add SSHD to &lt;code&gt;.profile&lt;/code&gt;, so starting Termux automatically starts the SSH server:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;sshd&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; ~/.profile&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 class="relative group"&gt;1.2. Computer side
 &lt;div id="12-computer-side" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#12-computer-side" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;Install the OpenSSH client and server on the computer.&lt;/p&gt;
&lt;p&gt;On Linux/MacOS, install OpenSSH from the package manager. On Windows, refer to &lt;a href="https://learn.microsoft.com/zh-tw/windows-server/administration/openssh/openssh_install_firstuse" target="_blank" rel="noreferrer"&gt;Microsoft&amp;rsquo;s documentation&lt;/a&gt; to install OpenSSH.&lt;/p&gt;
&lt;p&gt;Do not forget to open port 22 in the firewall.&lt;/p&gt;

&lt;h2 class="relative group"&gt;2. Start SSH connections
 &lt;div id="2-start-ssh-connections" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#2-start-ssh-connections" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;First, connect the computer and phone to the same Wi-Fi.&lt;/p&gt;
&lt;p&gt;Next, run the following commands on the computer to get the computer&amp;rsquo;s local IP,&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Linux, MacOS:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ifconfig
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Windows:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ipconfig&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The computer&amp;rsquo;s local IP is shown in the red box below; my computer&amp;rsquo;s local IP is &lt;code&gt;192.168.1.103&lt;/code&gt;:
&lt;figure&gt;
 &lt;img
 class="my-0 rounded-md"
 loading="lazy"
 decoding="async"
 fetchpriority="low"
 alt=""
 src="https://i.imgur.com/voaD5ow.png"
 onerror="this.onerror=null;this.src='https://ivonblog.com/images/cannotloadimage.avif'"
 &gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Run this command in Termux on the phone to get the local IP:&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ifconfig&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The phone&amp;rsquo;s local IP is shown in the red box below; my phone&amp;rsquo;s local IP is &lt;code&gt;192.168.1.101&lt;/code&gt;:
&lt;figure&gt;
 &lt;img
 class="my-0 rounded-md"
 loading="lazy"
 decoding="async"
 fetchpriority="low"
 alt=""
 src="https://i.imgur.com/me2G4ni.png"
 onerror="this.onerror=null;this.src='https://ivonblog.com/images/cannotloadimage.avif'"
 &gt;&lt;/figure&gt;&lt;/p&gt;

&lt;h3 class="relative group"&gt;2.1. SSH from the phone to the computer
 &lt;div id="21-ssh-from-the-phone-to-the-computer" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#21-ssh-from-the-phone-to-the-computer" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Enter the command in Termux on the phone to connect to the computer.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# [user account@computer IP] [port]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ssh ivon@192.168.1.103 -p &lt;span class="m"&gt;22&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="2"&gt;
&lt;li&gt;
&lt;p&gt;Enter yes to continue, then enter the user password&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After successfully logging in to the computer, you will enter the shell. Enter &lt;code&gt;exit&lt;/code&gt; to quit.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 class="relative group"&gt;2.2. SSH from the computer to the phone
 &lt;div id="22-ssh-from-the-computer-to-the-phone" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#22-ssh-from-the-computer-to-the-phone" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;Phones usually do not have firewall issues, but note that Termux&amp;rsquo;s SSH server port is &lt;strong&gt;8022&lt;/strong&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open a terminal on the computer and SSH to the phone:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# [user account@phone IP] [port]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ssh user@192.168.1.101 -p &lt;span class="m"&gt;8022&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="2"&gt;
&lt;li&gt;Enter yes to continue, then enter the user password. You will then see Termux&amp;rsquo;s welcome message, which means login succeeded.
&lt;figure&gt;
 &lt;img
 class="my-0 rounded-md"
 loading="lazy"
 decoding="async"
 fetchpriority="low"
 alt=""
 src="https://i.imgur.com/8xr5fKU.png"
 onerror="this.onerror=null;this.src='https://ivonblog.com/images/cannotloadimage.avif'"
 &gt;&lt;/figure&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 class="relative group"&gt;3. Transfer files through SSH SCP
 &lt;div id="3-transfer-files-through-ssh-scp" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#3-transfer-files-through-ssh-scp" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;In &lt;a href="https://ivonblog.com/en-us/posts/how-to-use-termux/" target="_blank" rel="noreferrer"&gt;Termux Usage&lt;/a&gt;, I mentioned the &lt;code&gt;termux-setup-storage&lt;/code&gt; command. It mounts the phone&amp;rsquo;s &amp;ldquo;internal storage&amp;rdquo; under Termux&amp;rsquo;s &lt;code&gt;storage&lt;/code&gt; directory. What does this mean? We can access the phone&amp;rsquo;s files from Termux, including photos and documents, and transfer files back and forth with the computer through the SCP command.&lt;/p&gt;</description></item></channel></rss>