Switching ADB from Root to User Mode

Switching ADB from Root to User Mode

21 May 2024 Stephan Petzl Leave a comment Tech-Help

Android Debug Bridge (ADB) is a versatile command-line tool that lets you communicate with a device. The ADB command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device. It’s a client-server program that includes three components:

  • A client, which sends commands.
  • A daemon (adbd), which runs commands on a device.
  • A server, which manages communication between the client and the daemon.

When working with ADB, you might need to switch between operating as a regular user and as root (superuser) to execute certain commands. In this article, we’ll guide you through the process of reverting ADB to user mode after having switched to root mode.

Reverting to User Mode

If you’ve initiated ADB in root mode using adb root and wish to revert to the non-root user mode, you can simply use the following command:

adb unroot

This command will restart the ADB daemon (adbd) as a non-root user, allowing you to continue your work in user mode.

Alternative Method

Should the above method not yield the desired results, there’s an alternative approach you can take. This involves manually changing the property that governs ADB’s root mode and restarting the daemon:

adb shell 'setprop service.adb.root 0; setprop ctl.restart adbd'

This command works by setting the service.adb.root property to 0, which corresponds to non-root mode, and then restarting the ADB daemon on the device.

Understanding the Process

It’s important to understand that the adb kill-server and adb start-server commands only affect the ADB server on your development machine, not the daemon running on the device itself. The methods provided above directly affect the daemon running on the device, which is why they are effective in switching between root and user modes.

Repeato: Streamlining Your Testing Workflow

When testing apps using ADB, it’s crucial to have tools that can simplify and automate the process. Repeato is a No-code test automation tool for iOS and Android that can significantly enhance your testing workflow. With its ability to execute ADB commands through script steps, Repeato can help you time and send ADB commands in sequence, which is especially useful when you need to perform actions like switching ADB modes during automated testing.

To learn more about how Repeato can streamline your app testing and to explore its computer vision and AI capabilities, visit our documentation or download the tool from our download page.

For additional resources on ADB commands and troubleshooting, feel free to peruse our blog articles on topics like restarting an Android device from the command line and troubleshooting ADB offline status.

Like this article? there’s more where that came from!