Connect to Android Device from PC using SSH
Use Termux for connecting to Android device from your laptop or desktop.
Last updated
Use Termux for connecting to Android device from your laptop or desktop.
Last updated
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.
After that, store the generated files (id_25519_android
, id_25519_android.pub
) into ~/.ssh
folder.
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 . According to the official, installing from Google Play is deprecated.
After installing Termux, open it and execute the following commands.
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.
openssh
: Required to start SSH server.
iproute2
: Required to check the SSH port number.
nmap
: Required to confirm the SSH server is running.
After installing openssh
, our SSH host configurations and keys are stored under /data/data/com.termux/files/usr/etc/ssh/
.
By default, Termux does not have access to Android storage, so we need to create a symbolic link to it wiht termux-setup-storage
command.
After that storage
directory is generated under the Termus home directory (/data/data/com.termux/files/home
) which is a symbolic link to /storage
directory.
Out id_ed25519_android.pub
file which was transferred from our machine may exist in this directory.
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.
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 8022
.
If successful, we can take control of our Android device from our machine.
After finish playing with Android, it’s better to stop the SSH server.
To check the SSH daemon stops, use ps
or nmap
.
Please see for details.