This page describes how to set up a termux ssh server running as root by using solely adb root, without needing any other rooting app (such as Magisk, SuperSu, Kingroot, ...)

Preparation

In order to do this, your phone or tablet needs to have USB debugging and root USB debugging enabled.

  1. Go to Settings->About tablet and tap 7 times on Build number to enable Developer options
  2. Go to Settings->System->Developer options and enable both USB debugging and Rooted debugging
Moreover, Termux needs to be installed, with openssh-server, and at least one key authorized in ~/.ssh/authorized_keys

The script

Once your phone is ready, connect it with an USB cable to your computer, download the script, and run it.

What the script does:

Using the ssh server

Just connect to port 8122 on the tablet or phone:

ssh -p 8122 mydevice

If you've included the phone or tablet's own ssh public key into ~/.ssh/authorized_keys, you can even connect from the device to itself to acquire root:

ssh -p 8122 localhost

Cleanup

Once installed, you can again remove USB debugging and Rooted debugging, and the rooted ssh still continues to work. The ssh server continues to work even after a LineaOS upgrade, thanks to a /system/addon.d script

Future work