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.
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.
The benefit of these tools is that their ports are shared with SSH, and SSH encrypted communication can improve transfer security.
Incidentally, KDE Connect, which connects phones and computers, also uses SSH. If you do not like typing commands, you can try the KDE Connect app first.
1. Install OpenSSH#
1.1. Phone side#
Please read first: How to Use Termux
- Install OpenSSH in Termux, including client and server:
pkg install openssh- Termux’s virtual user account is always
user. Enter this command, type a password of 4 or more digits, and press Enter:
passwd- Then run this command in Termux to start the SSH server.
sshd- Since SSHD closes after you exit Termux, you can add SSHD to
.profile, so starting Termux automatically starts the SSH server:
echo "sshd" >> ~/.profile1.2. Computer side#
Install the OpenSSH client and server on the computer.
On Linux/MacOS, install OpenSSH from the package manager. On Windows, refer to Microsoft’s documentation to install OpenSSH.
Do not forget to open port 22 in the firewall.
2. Start SSH connections#
First, connect the computer and phone to the same Wi-Fi.
Next, run the following commands on the computer to get the computer’s local IP,
# Linux, MacOS:
ifconfig
# Windows:
ipconfigThe computer’s local IP is shown in the red box below; my computer’s local IP is 192.168.1.103:
Run this command in Termux on the phone to get the local IP:
ifconfigThe phone’s local IP is shown in the red box below; my phone’s local IP is 192.168.1.101:
2.1. SSH from the phone to the computer#
- Enter the command in Termux on the phone to connect to the computer.
# [user account@computer IP] [port]
ssh ivon@192.168.1.103 -p 22Enter yes to continue, then enter the user password
After successfully logging in to the computer, you will enter the shell. Enter
exitto quit.
2.2. SSH from the computer to the phone#
Phones usually do not have firewall issues, but note that Termux’s SSH server port is 8022.
- Open a terminal on the computer and SSH to the phone:
# [user account@phone IP] [port]
ssh user@192.168.1.101 -p 8022- Enter yes to continue, then enter the user password. You will then see Termux’s welcome message, which means login succeeded.

3. Transfer files through SSH SCP#
In Termux Usage, I mentioned the termux-setup-storage command. It mounts the phone’s “internal storage” under Termux’s storage directory. What does this mean? We can access the phone’s files from Termux, including photos and documents, and transfer files back and forth with the computer through the SCP command.
3.1. Send files from the phone to the computer#
Run the following command in Termux to send foo.jpeg from the phone’s camera directory to the computer’s Pictures directory:
# [port] [phone:directory] [computer:directory]
scp -P 22 ~/storage/shared/DCIM/foo.jpeg ivon@192.168.1.103:~/Pictures3.2. Send files from the computer to the phone#
Run the following command in Termux to send foo.jpeg from the computer’s Pictures directory to the camera directory in the phone’s internal storage:
# [port] [computer:directory] [phone:directory]
scp -P 22 ivon@192.168.1.103:~/Pictures/foo.jpeg ~/storage/shared/DCIM/4. Use SSHFS to mount remote directories#
SSHFS is a tool that mounts remote filesystems through an SSH tunnel. Compared with the SCP command, which is only used for transferring files, SSHFS is more like the concept of an “SMB shared folder”, making it convenient to transfer and browse large numbers of photos and videos, without thumbnails failing to show up like with MTP.
Because it is encrypted, you need to tune the command appropriately for faster transfer speed. For details, refer to the answer on Stack Exchange. Disabling DNS on the computer-side SSH can also speed up transfers.
Linux supports mounting SSHFS directly; Windows and MacOS need additional software. For details, refer to G.T.Wang’s website.
4.1. Mount the phone directory on the computer#
- Open a terminal and create a
remotedirectory for mounting
mkdir ~/remote- Confirm that SSHD in Termux on the phone is running. Mount the
DCIMdirectory in the phone’s internal storage to the computer’s remote directory:
# [phone port] [phone:directory] [computer:directory]
sshfs -p 8022 user@192.168.1.101:storage/shared/DCIM ~/remoteEnter yes, then enter the password, and you can see files under the phone’s
DCIMdirectory in theremotedirectory
To unmount, run the following command:
fusermount -u ~/remote4.2. Mount the computer directory on the phone#
Note: the phone side requires root privileges, and Termux cannot mount SSHFS directly. Phones without root privileges can instead use “Add SFTP connection” in Material Files, which functions similarly to SSHFS.
Use a file manager app to create a directory called
remotein the phone’s internal storage.Download the EasySSHFS app
Tap Add in the upper left corner to add a mount point. Then fill in the local mount point name, computer username, computer local IP, and computer password in order. Skip Identity File. Also fill in the computer directory to mount and the local mount directory.
For example, the following example mounts the computer’s
/home/ivon/Picturesdirectory to theremotedirectory in the phone’s internal storage.
Press Save in the upper right corner. Slide out the left-side options, press Mount points to return to the home page, then press Mount. On success, it will show
mounted.
Now you can see the computer’s files in the remote directory. To unmount, return to EasySSHFS and press Umount.

5. Automatically sync photo files to the computer with Rsync#
Rsync is a tool for synchronizing files. It is very fast, and file synchronization between different devices goes through an SSH tunnel. In addition, Termux can use Crontab or work with Tasker (proprietary software) to set scheduled command execution. Combining the two can achieve the need to “periodically back up phone photos to the computer.”
- First, install Rsync in Termux:
pkg install rsyncThe computer also needs Rsync installed. On Linux/MacOS, install it through the package manager; on Windows, install cwRsync.
Start the first synchronization! Suppose I want to synchronize the
DCIMdirectory in the phone’s internal storage to the~/Picturesdirectory on the computer, without deleting local files. Then run the following command in Termux:
# Show progress [phone:directory] [computer:directory]
rsync -av --progress -e ssh ~/storage/shared/DCIM ivon@192.168.1.103:~/PicturesAfter entering the password, synchronization starts. To avoid typing the password every time, refer to the steps below for using an SSH key instead of a login password.
Next, set an automatic backup schedule. Choose one of the two.
5.1 Crontab in the background#
- Run the following commands in Termux:
pkg install nano cronie termux-services
sv-enable crond
crontab -e- Then nano should open automatically. Fill the following content into crontab, then enter CTRL+X to save:
# Run the command to sync to the computer every night at 11:30
30 23 * * * /home/gtwang/script.sh --your --parameter- Pull down the notification shade and tap
ACQUIRE WAKELOCkfor Termux. This way, as long as Termux is open, the Rsync backup will automatically execute when the time arrives.
5.2. Automatic scheduling with Tasker#
Install the Tasker app, then install Termux Tasker, and configure conditions yourself to run the Rsync command at specified times.
6. Other uses for Termux SSH#
6.1. SSH Forwarding#
You can transmit the X server graphical interface and PulseAudio audio to another computer through an SSH Tunnel.
6.2. Use an SSH key instead of a login password#
An SSH key is a connection method that uses cryptographic keys for authentication, and is more secure than password authentication. It is also used if you want to access your own Github repositories with Termux.
Below is a demonstration of generating an SSH key on the phone side, then sending it to the computer. This way, SSH from the phone to the computer will no longer require typing a password.
- Generate an RSA key in Termux:
ssh-keygen- The key file is located at
~/.ssh/id_rsa.pub. View it with the following command and copy the long key string that starts with ssh
cat ~/.ssh/id_rsa.pub- Connect to the computer with SSH
ssh ivon@192.168.1.103- Write the key into
authorized_keys. For example, on Linux this file is under the~/.sshdirectory:
echo "金鑰字串" >> ~/.ssh/authorized_keys- Log out. After that, the phone can connect to the computer directly without entering a password.


