2

I have a couple of tasks I want to accomplish on Android 6.0.1 and they need root access when I run them on the device. This target device is not rooted.

Can I use adb from a PC to run commands just as if I would using a Terminal Emulator on a rooted Android? I thought adb gives some sort of unrestricted temporary access (like temporary root).

2

I thought adb gives some sort of unrestricted temporary access (like temporary root).

When you open an ordinary terminal emulator app, you're shown a terminal and are automatically logged in as a particular user. The User ID of this particular user is the user ID of your displayed terminal emulator app. Such user and app is considered untrustworthy and is not allowed to do quite a lot of things. You can see the blacklisted items in the source code of untrusted_app.te.

ADB on the other hand when interfaces with the device gets to use the user ID 2000. This user is called shell and can do quite a lot of things for the purpose of debugging but still cannot meet the intricate demands of an end user1. Unless the Android offers a mechanism to switch to another user at will (such as 'su'; not graphical but console), the end user is limited to make any good use of shell user only when device is connected to PC in debugging mode. Follow the source code of shell.te to know about the privileges shell user enjoys.

In short, if the Android is not rooted shell user obviously comes as a winner because of privileges granted to it in contrast to an untrustworthy user, but it does not serve as a good substitute for superuser (su). In addition to that, as I noted above it comes with a cost.

Related resource: user IDs which come defined in Android


1 Temporary or otherwise, root user always have the user ID 0.

| improve this answer | |
0

adb does not grant automatic root access unless you modify the system to run adbd as root (and if you're able to do that, you probably have root anyways) or if you are running an insecure development ROM (typically only for Nexus devices) and run adb root.

So normally, you have to be rooted and run su within adb shell just like you would within within a terminal emulator app.

ADB does run with some extra permissions, however (see this comment). A terminal emulator app could request some of those permissions, but if it doesn't then you'll need root to make use of them.

| 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.