Set up SSH access to your Android mobile device over LAN using Termux.
- Open the Termux app and update & upgrade packages. Run:
Code language: Shell Session (shell)
pkg update pkg upgrade
- During upgrade, you may be prompted to replace a version of a packages with the maintainer’s version. Pick the default option (No) for now by just hitting enter.
- Install the OpenSSH package with
pkg install openssh
- Set up access for Termux to your to mobile’s storage with
- Create a password for the default Termux user with
- Get your Termux username with
- Start SSH server on your device with the command
- Get your mobile’s LAN IP address from your device’s Wi-Fi settings. You can usually get this from the info page of the network you are connected to.
- Now from your PC’s command line (Linux, Mac or Windows PowerShell) you can access your mobile with
ssh -p 8022 u02..@192.168.x.x. 8022 is the default port used by Termux. Your PC should be connected to the same Wi-Fi network as your Android.
- When you try to connect, you’ll be prompted for a password. Enter your Termux user’s password that you created in Step 4 above.
- You’re now logged into your Android and you can use terminal commands to access your device’s files or copy files between your PC and your mobile.
Setting up password-less login
If you already have an SSH key for your PC, you can copy the public key to your mobile to login without a password. To copy your PC’s public key, from your PC:
Code language: PHP (php)
# Replace the location & name of your key. Also change the username and your Android's IP ssh-copy-id -p 8022 -i ~/keys-folder/key_name.pub email@example.com
If you don’t have an SSH key, you can create one on your PC with
ssh-keygen. Run the below command in your PC’s Terminal. In Windows, you can run this in PowerShell.
ssh-keygen -t rsa -b 2048 -C "key_name@domain"
These steps enable SSH access to your Android over LAN. If you need SSH access to an Android device when it is not connected to your local network, I recommended creating your own private VPN with Tailscale.