I've recently started using the amazing Termux terminal app and linux environment. It provides a wealth of full-function terminal utilities. It would be great to be able to access these utilities from other consoles, especially when connected via ssh or adb shell. I've managed to make some functionality available by setting my PATH and LD_LIBRARY_PATH environment variables to the same values used by Termux's shell, but there are permissions problems and it seems messy.

Is there a way to ssh in to a Termux session? Termux doesn't seem to provide an ssh server package. Even if it did, presumably that server, and thus the ssh session granted by it, would run as a separate user from the termux user, resulting in similar permissions problems.

Is there a supported way to access the Termux user environment from other consoles?

  • I looked at various tutorials and I could only figure out how to connect via USB (wired) tether. I couldn't figure out how to get a wireless IP for the sshd server in Termux. If anyone is having trouble finding the IP address of your phone, plug it into your PC (with USB cable) and then look for the "Default Route" on the new wired connection on your PC, that's the only way I could get it working. Also you may need "whoami" and/or "passwd" in Termux to get the username. Port defaults to 8022. PS: Tried sshuttle through the Termux sshd and my ISP still throttles it down to pathetic .5 Mbps :-/ – PJ Brunet Jun 12 at 23:52
  • @PJBrunet what did you try on termux to get the Ip Adress? – user3123159 Nov 12 at 16:31
  • For getting the ip of a device, Linux-Know-How might help. As a starter I recommend Lpic1. – user3123159 Nov 12 at 16:39

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.

| improve this answer | |
  • 1
    Wow, they should really mention that in the package description, which just says that it is a "Secure shell for logging in to a remote machine". – intuited Sep 1 '16 at 17:23
  • 8
    Password authentication is supported. You need to run passwd to set a new password for your SSH server. However, what doesn't work is usernames (i.e. everyone can log in with every username with that one password), AFAIK. – MAChitgarha Jun 4 '19 at 21:29
  • You can launch sshd on every boot using wiki.termux.com/wiki/Termux:Boot – fuzzyTew May 9 at 19:59
  • "wlan0" didn't give me a useable IP address – PJ Brunet Jun 12 at 21:10
  • @MAChitgarha your point is essential, otherwise there is no chance to connect. Well done! – user3123159 Nov 12 at 16:37

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,


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
| improve this answer | |
  • Password authentication IS now supported. – user3123159 Nov 7 at 12:50

On your knees and bow,

Ip_Address_Of_Remote_Host =

(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 user@

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 user@

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


file from your Remote machine to the termux


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 user@ ~/.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

| improve this answer | |
  • For anybody with a slight understanding of SSH this should be straight forward for those who are new to GNU/Linux paths are what you need to be focused on. My next port of call is to see if X forwarding is possible for then it opens up the possibility of using the productivity suits on your desktop but writing to the termux machine, let me expand you will be able to use LibraOffice software on the termux machine but have it displayed on the desktop without lagging/latency this is the power of GNU/Linux. – Michael Hughes Jul 21 '18 at 12:06

These are Android commands to run on Termux and setup a SSH client and server, allowing to connect from your desktop to your Android and vice-versa. This does not cover the SSH server and client set up on your desktop computer.

Using the SSH server https://termux.com/ssh.html

apt update
apt upgrade
apt install openssh

Here you can create a password for your keys and use it to connect to your computer, if you like a password. Otherwise, leave them in blank and no passwords are required, other than your DESKTOP user computer password.

How can I set up password-less SSH login? https://askubuntu.com/questions/46930/how-can-i-set-up-password-less-ssh-login

ssh-keygen -b 4096 -t rsa

This allows you to connect from your ANDROID to your DESKTOP by SSH connection without your ANDROID user password (as passwords are not supported by termux sshd server)

3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id https://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id

ssh-copy-id -i ~/.ssh/id_rsa.pub your_desktop_ssh_user@YOUR.DESKTOP.IP.ADDRESS

This allows you to connect from your DESKTOP to your ANDROID by SSH connection without your ANDROID user password (if you want to use your's computer user password, skip this command)

  1. First Option Accessing termux user environment from other consoles Accessing termux user environment from other consoles

    scp your_desktop_ssh_user@YOUR.DESKTOP.IP.ADDRESS:~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
  2. Second Option How do I add SSH Keys to authorized_keys file? https://askubuntu.com/questions/46424/how-do-i-add-ssh-keys-to-authorized-keys-file

    cat ~/.ssh/id_rsa.pub | ssh your_desktop_ssh_user@YOUR.DESKTOP.IP.ADDRESS "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Scripts and notes for setting up and using SSHd on your Android device using Termux https://github.com/tomhiggins/TermuxSSHDsetup

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

ssh blank passphrase but still asking for it https://serverfault.com/questions/845623/ssh-blank-passphrase-but-still-asking-for-it

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa.pub
chmod 600 ~/.ssh/known_hosts
chmod 600 ~/.ssh/authorized_keys

Start the server by executing sshd (which will start it on the default port 8022) and run logcat -s 'syslog:*' to view the log output from the server process. Execute pkill sshd to stop the server.

logcat -s 'syslog:*'
pkill sshd

Finally, connecting from one to another and vice-versa:

Connecting from your ANDROID to your DESKTOP (the usage of your DESKTOP user password can be optional)

ssh your_desktop_ssh_user@YOUR.DESKTOP.IP.ADDRESS

Connecting from your DESKTOP to your ANDROID (must not to use your ANDROID user password)

Since Termux is a single-user system you may connect as any user - regardless of your specified username you will login as the only Termux user available.

The Termux sshd binary does not support password logins, so a key needs to be authorized in ~/.ssh/authorized_keys before connecting. Use ssh-keygen to generate a new one if desired.

ssh -p 8022 -i ~/.ssh/id_rsa IP.OF.YOUR.ANDROID

(ANDROID) If you still have trouble logging on navigate to file and activate these two key pairs: /data/data/com.termux/files/usr/etc/ssh/sshd_config

ChallengeResponseAuthentication no
PubkeyAuthentication yes

Extra: Locking and unlocking the file system from read-only to read-write and vice-versa.

How to copy files to an Android emulator’s data directory with ‘adb push’ https://alvinalexander.com/android/how-copy-files-android-device-emulator-adb-push-read-only-error

mount -o rw,remount rootfs /

Revert the changes back after finishing the changes!

cat /proc/mounts
mount -o ro,remount rootfs /
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.