Connect to Android Device from PC using SSH
Last modified: 2023-11-05
Use Termux for connecting to Android device from your laptop or desktop.
In our machine, we need to generate SSH key pair for connecting to SSH server of Android device.
After running the following command, there's no problem with no passphrase if it's for testing purpose.
ssh-keygen -t ed25519 -f id_ed25519_android
After that, store the generated files (
# If `.ssh` directory does not exist, create a new one. mkdir -p ~/.ssh mv id_ed25519_android* ~/.ssh/
We need to send our
id_25519_android.pub to an Android device. There are various ways to do that such as bellow:
- Using a USB cable.
- Using Bluetooth.
- Using email such as Gmail.
Install it from F-Droid. According to the official, installing from Google Play is deprecated.
After installing Termux, open it and execute the following commands.
pkg update pkg upgrade apt update apt upgrade
If you got the error “repository is under maintenance or down (wrong sources.list URL?)”, change the mirrors using
termux-change-repo or modify
sources.list directly as follows.
echo "deb https://grimler.se/termux-packages-24 stable main" > $PREFIX/etc/apt/sources.list echo "deb https://grimler.se/termux-packages-24 stable main" > $PREFIX/etc/apt/sources.list.d/game.list echo "deb https://grimler.se/termux-packages-24 stable main" > $PREFIX/etc/apt/sources.list.d/science.list
Please see the termux package issue for details.
pkg install openssh pkg install iproute2 pkg install nmap
openssh: Required to start SSH server.
iproute2: Required to check the SSH port number.
nmap: Required to confirm the SSH server is running.
openssh, our SSH host configurations and keys are stored under
By default, Termux does not have access to Android storage, so we need to create a symbolic link to it wiht
storage directory is generated under the Termus home directory (
/data/data/com.termux/files/home) which is a symbolic link to
id_ed25519_android.pub file which was transferred from our machine may exist in this directory.
cd /data/data/com.termux/files/home/storage ls # downloads movies music pictures shared cd downloads ls # id_ed25519_android.pub # Check physical directory pwd -P # /storage/emulated/0/Download
cat /data/data/com.termux/files/home/storage/downloads/id_ed25519.pub >> ~/.ssh/authorized_keys # Change permission chmod 600 ~/.ssh/authorized_keys
In Android device, run
sshd command to start SSH server.
In Android device, check the SSH port number using
nmap command. This port number will be used for connecting the SSH server from our machine.
In Android device, run the following command to retrieve the IP addressd on the network.
Please note that both our machine (laptop or desktop) and Android device must connect to the same WiFi network.
ip -4 addr
We should see
wlan0 interface and the IP address such as
192.168.11.123 in the
inet section. Take a note this address.
In our machine, run the following command.
Assume that the Android’s IP address is
192.168.11.123 and the SSH port number is
If successful, we can take control of our Android device from our machine.
ssh -i ~/.ssh/id_ed25519_android 192.168.11.123 -p 8022 $ whoami u0_a123
After finish playing with Android, it’s better to stop the SSH server.
# Check PID of `sshd` ps -e | grep sshd # Kill the process kill -9 <PID>
To check the SSH daemon stops, use
ps -e nmap localhost