Deltamodel

a structured approach ...

SSH access to Android smartphones with MacOS or Linux

There are many reasons why accessing an Android smartphone via SSH makes sense. For example, to use an older device that would otherwise have been discarded as a home server or as a control center for a NAS. To access an Android smartphone via SSH, the following way has proven successful.

  1. install Termux on the android device
  2. install and setup openssh in termux
  3. connect to the smartphone

Installing Termux

The fastest way to install Termux is via the Google Playstore or via FDroid.

install and setup openssh in termux

Enable termux to access the phone’s file system, update the package management and install openssh.

termux-setup-storage
pkg update
pkg install openssh

For access via SSH, generate a key pair and add the generated public key file (here id_rsa.pub) to the list of authorized keys. Copy the private key to the file directory of the smartphone (here download folder) to transfer it later to the client from which the smartphone will be accessed.

ssh-keygen
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
cp ~/.ssh/id_rsa ~/storage/shared/Download

The SSH server is started with sshd.

sshd

SSH access from the client

  • copy the private key from the smartphone to the client, e.g. to the directory ~/.ssh/keyfiles.
  • for security reasons, access to the key file should be restricted under MacOS and Linux (400 read only, 600 write).
  • the access is done normally via SSH
chmod 400 ~/.ssh/keyfiles/id_rsa
ssh your_smartphone -p 8022 -i ~/.ssh/keyfiles/id_rsa