Android - Accessing termux user environment from other consoles

Termux does provide the openssh package, which contains both the ssh client and the sshd server.

Install the package with: apt install openssh, then start the server with sshd - it will run on port 8022 by default, so connect to it with ssh -p 8022 DEVICE_IP, and you can find the device wifi ip using ip addr list wlan0.

Password authentication is not supported, so you need to setup $HOME/.ssh/authorized_keys.

After you have connected you will run as the normal Termux user with environment variables setup correctly.


You need to install openssh in termux by running

pkg install openssh

and then, on the device you want to ssh from, generate a Public ID Key,

ssh-keygen

and just confirm and down change anything, then do

cat ~/.ssh/id_rsa.pub

and copy the output into ~/.ssh/authorized_keys and restart the sshd server and try to ssh,

if you encounter any errors, check the authorized_keys file and makesure your public key is all on one line

You have to do these steps above because Termux sshd doesnt support password logins, (IE, ssh user@ip_address then entering a password)

you have to ssh into termux using

ssh termux-ip-here -p 8022

On your knees and bow,

Ip_Address_Of_Remote_Host = 192.168.1.20

(Assuming you have generated a key on the termux machine using

ssh-keygen -t rsa

There is a space inbetween ssh-keygen and -t and copied the key to Remote_Host using that machines log-on details

ssh-copy-id [email protected]).

There is a space inbetween ssh-copy-id and user

You should now be able to log on to the remote host without using a password.

ssh [email protected]

The rsa key generated above is not the key you place into the authorized_keys file on the termux machine.

The issue is getting the

id_rsa.pub

file from your Remote machine to the termux

~/.ssh/authorized_keys

file on the Local system (phone) the solution I used was scp, this command confuses a lot of people but if viewed from the position that it is just a cp command it's mysticism vanishes

cp file_to_copy where_to_copy_file

This command is run from the Termux machine (phone)

scp [email protected]:/home/user/.ssh/id_rsa.pub ~/.ssh/authorized_keys

There is a space inbetween id_rsa.pub and ~/

The path to your .ssh directory may be different just make sure it is the correct path you enter into he above command.

If you still have trouble logging on navigate to the

/data/data/com.termux/files/usr/etc/ssh/sshd_config file

Activate these two key pairs

ChallengeResponseAuthentication no

PubkeyAuthentication yes

Tags:

Terminal

Ssh