Is it possible to run adb and fastboot commands using Termux terminal emulator? I am wanting to run commands from one Huawei T3 7 to another using USB/OTG cable. Need to unlock bootloader but have no access to a PC or laptop.


1 Answer 1


This question is nearly a duplicate of this which has a detailed answer by @Firelord, except the Termux part. As mention by @DeathMaskSalesman in comment, Termux is more like a Linux environment, but so far it doesn't have adb and fastboot in repositories, though proposed. Most probably because they are meant for rooted devices. But you can use static binaries (e.g. this or this) on Termux like on usual Terminal emulator app. Make sure to set proper environment variables (TMPDIR, HOME or HOMEDIR).

However you won't be able to run each of them without root because only members of AID_USB group are able to read devices in /dev/bus/usb/ (1). Furthermore SELinux restricts unprivileged apps' access to /sys and /dev.

For adb there's a workaround if both devices are connected to same network e.g. Wi-Fi or hotspot. adbd can be run to listen on TCP socket instead of USB. It's possible if before turning on "USB Debugging" property service.adb.tcp.port (2) is set to some port (first default is 5555). Apps can't set properties, so to do this using setprop on adb shell or by simply executing adb tcpip 5555, you need to connect the target device to a PC over USB. Then all you have to do from Termux before sending commands is:

~$ adb connect <IP>:5555

But service.adb.tcp.port is reset on reboots and you have to set it again. There is another property persist.adb.tcp.port which persists across reboots but it's meant only for testing and SELinux won't let you set this without root or some system app running with UID 1000.

Some custom ROMs have built-in toggle to set service.adb.tcp.port. But for fastboot root is must. However it's possible on Android to access USB OTG devices through android.hardware.usb APIs. fastboot-mobile is an unofficial library from Google to send fastboot commands over OTG. This app (I have no affiliation) also provides similar limited functionality.

  • 1
    @alecxs so how does Tasker sets service.adb.tcp.port to 5555 without connecting to PC? On stock Android Dev Options don't have ADB over network. So the only way to set service.adb.tcp.port is through adb because apps cannot set properties. service.adb.tcp.port has SELinux context shell_prop, so adbd can set it. But persist.adb.tcp.port doesn't have a defined SELinux context, so it's set with context default_prop, which can only be set by init on user builds. So the both properties can be set permanently only (with root or) on ROMs with modified SELinux policy. Commented Feb 8, 2020 at 20:43
  • 1
    you must be right. the reddit post say it's using setprop but to me it looks like chicken egg dilemma
    – alecxs
    Commented Feb 8, 2020 at 20:54
  • 2
    If you restart adb in tcp mode than Tasker can also send adb commands to Android. This would work so long as the device is not rebooted as that would again require adb restart in tcp mode. All in all, adb support of Tasker would help if you don't ever restart the device.
    – Firelord
    Commented Jan 30, 2021 at 20:24

You must log in to answer this question.

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