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.
The fastest way to install Termux is via the Google Playstore or via FDroid.
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
chmod 400 ~/.ssh/keyfiles/id_rsa
ssh your_smartphone -p 8022 -i ~/.ssh/keyfiles/id_rsa