Can't I somehow force running a command as `com.termux` user thanks to `root`?
May 5, 6:23pm
On LineageOS (and most modern Android versions), the run-as command enforces SELinux and app sandboxing restrictions, even for the root user. The error run-as: package not debuggable: com.termux means that Termux is not marked as a debuggable app in its manifest, so run-as refuses to switch to its user context—even with root privileges.
Workarounds to Run Commands as com.termux User
1. Temporarily Make Termux Debuggable
Requires: Root access and a way to modify app manifests (e.g., apktool or smali patching).
Steps:
Extract Termux’s APK:
bash
apktool d /data/app/com.termux-*/base.apk -o termux_mod
Edit AndroidManifest.xml to add android:debuggable="true" to the <application> tag.
Rebuild and reinstall the APK:
bash
apktool b termux_mod -o termux_debug.apk
adb install -r termux_debug.apk
Now run-as com.termux should work.
Downside: Requires rebuilding the APK, and updates may revert the change.
2. Use su to Switch to Termux’s UID
If Termux’s UID is known (e.g., u0_a123), you can use su to switch to it:
bash
su -c "su u0_a123 -c 'export PATH=/data/data/com.termux/files/usr/bin:\$PATH; bash -i'"
Find Termux’s UID:
bash
grep termux /data/system/packages.list
or
bash
ls -n /data/data | grep com.termux
Note: This may still fail if SELinux denies the transition.
3. Directly Access Termux’s Files as Root
If your goal is to run scripts or access files in Termux’s directory, you can do so directly as root:
bash
cd /data/data/com.termux/files/usr/bin
./bash -lic 'export PATH=/data/data/com.termux/files/usr/bin:$PATH; bash -i'
Limitation: Some Termux-specific environment variables (e.g., $PREFIX) may not be set.
4. Use nsenter to Join Termux’s Namespace
If Termux is running, you can find its PID and join its namespace: