Access your Android device over SSH with Termux

Add RSS feed to Reader and sync to Readwise.

Set up SSH access to your Android mobile device over LAN using Termux.

Termux is an Android app that provides terminal emulation and access to Linux packages. With Termux you can install OpenSSH and set up an SSH server on Android. You can install Termux from F-Droid.

After installing:

  1. Open the Termux app and update & upgrade packages. Run:
pkg update
pkg upgrade
Code language: Shell Session (shell)
  • 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.

  1. Install the OpenSSH package with pkg install openssh
  2. Set up access for Termux to your to mobile’s storage with termux-setup-storage
  3. Create a password for the default Termux user with passwd
  4. Get your Termux username with whoami
  5. Start SSH server on your device with the command sshd
  6. 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.
  7. 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.
  8. 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.
  9. 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:

# 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 termux_username@192.168.x.x
Code language: PHP (php)

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"
Code language: JavaScript (javascript)

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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *