4

I know how to open the termux app, run (for example) sv up sshd, and then interact with the Android device via ssh, rsync, etc. This is just an example, and the same is also true for any other termux initiated procedures.

However, to do this, it's necessary to perform that manual open and manual sv up sshd command in termux on the device itself.

I want to be able to perform that initial termux interaction from my desktop computer via adb without any direct interaction with the device itself, aside from plugging in the USB cable.

I have looked for solutions, but it seems like no one has come up with any way to interact with termux except by first actually manually opening that app on the device, which I do not want to do.

However, could I have overlooked something? I'm hoping that I indeed missed something, and that somehow I can start termux-initiated procedures via adb.

Does anyone know how that might be done?

Thank you in advance.

2
  • 2
    ADB shell is just an app (with UID 2000). And apps cannot access other apps' directories without root access. Related: How to run a program in an app context with Magisk?. // You can add sshd to .bashrc or .profile (so that it's started whenever Termux is launched) and then launch the app using adb shell am start -n com.termux/.HomeActivity. May 22, 2020 at 2:42
  • I have root, but even so, I see from the related article that I would have to run a complicated procedure to get the described functionality. However, using .profile and the am start command are doing what I want, so that's good enough for me, for now. Some day I will try to encapsulate that other multi-step procedure into some sort of utility, however, because programmatically running termux-based commands would be quite useful. Thank you!
    – HippoMan
    May 22, 2020 at 12:24

2 Answers 2

4
adb shell am start -n com.termux/.HomeActivity
adb shell input text "your command here"
adb shell input keyevent ENTER
3

Per the comment by Irfan Latif above, the following works:

  1. Launch termux

  2. Do the following:

    echo 'sv up sshd
    sshd started' > .profile
    
  3. Run this whenever I want to start sshd via adb:

    adb shell am start -n com.termux/.HomeActivity
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .