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
    • 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.
  2. Install the OpenSSSH package with pkg install openssh

  3. Set up access for Termux to your to mobile’s storage with termux-setup-storage

  4. Create a password for the default Termux user with passwd

  5. Get your Termux username with whoami

  6. Start SSH server on your device with the command sshd

  7. 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.

  8. 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.

  9. 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.

  10. 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

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.