With the brilliant Termux terminal emulator app you can run an SSH server on your Android.
Perviously I used SSHDroid to achieve this, but with Termux is much nicer because you have access to a working package manager.
Run the service
You neet to install the OpenSSH package
and use following command to start the ssh server.
And there you go. Your ssh service is now running on port 8022.
Adding your Public key
You can’t do password authentication in Termux, therefore you need to put your OpenSSH public key into the ~/.ssh/authorized_keys file.
This file will need to be created and permissions set to 600.
If you do not have a OpenSSH key pair yet, you can generate one with the following command:
You may or may not enter a passphrase and if you don’t specify otherwise, your key pair will have been saved under ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub. You can then add it to the ~/.ssh/authorized_keys with
Then you can test it by connecting to your ssh service
You can now use your private key (~/.ssh/id_rsa) to login to your Termux SSH Server. Simply copy it to your computer (by copying it to internal storage first [cp ~/.ssh/id_rsa /sdcard]) and use it in your ssh client.
If you’re using OpenSSH (on Linux or Cygwin) you can use it directly:
If you’re using PuTTY you will need to convert it to the PuTTY Private Key format first.
- Download and run PuTTYgen
- Load the private key (id_rsa)
- Save the private key as a *.ppk file.
- Download and run PuTTY
- Enter the IP address of your Android device and use port 8022
- Under Connection>SSH>Auth you can browse for the *.pkk file
- Click open
- You can leave “login as:” blank
You should now be connected to your Android device via SSH.
If it still doesn’t work
If it is still prompts you for a password you can enter sshd’s debug mode with the above command and see exactly why your key has been rejected. The reason usually are bad permission on either your home directory, your .ssh folder or your authorized_keys file.
The correct permissions are:
I hope in the future Termux will allow us to register sshd as a proper service which would automatically start on system boot. Right now I have the ‘sshd’ command in my .bashrc file and I am using Tasker to launch Termux after boot. You can also use the Termux widget to quickly start sshd with a widget.