adb shell su works but adb root does not

389,639

Solution 1

By design adb root command works in development builds only (i.e. eng and userdebug which have ro.debuggable=1 by default). So to enable the adb root command on your otherwise rooted device just add the ro.debuggable=1 line to one of the following files:

/system/build.prop
/system/default.prop
/data/local.prop

If you want adb shell to start as root by default - then add ro.secure=0 as well.

Alternatively you could use modified adbd binary (which does not check for ro.debuggable)

From https://android.googlesource.com/platform/system/core/+/master/adb/daemon/main.cpp

#if defined(ALLOW_ADBD_ROOT)
// The properties that affect `adb root` and `adb unroot` are ro.secure and
// ro.debuggable. In this context the names don't make the expected behavior
// particularly obvious.
//
// ro.debuggable:
//   Allowed to become root, but not necessarily the default. Set to 1 on
//   eng and userdebug builds.
//
// ro.secure:
//   Drop privileges by default. Set to 1 on userdebug and user builds.

Solution 2

In some developer-friendly ROMs you could just enable Root Access in Settings > Developer option > Root access. After that adb root becomes available. Unfortunately it does not work for most stock ROMs on the market.

Solution 3

I ran into this issue when trying to root the emulator, I found out it was because I was running the Nexus 5x emulator which had Google Play on it. Created a different emulator that didn't have google play and adb root will root the device for you. Hope this helps someone.

Solution 4

I use for enter su mode in abd shell

adb shell "su"

Solution 5

I have a rooted Samsung Galaxy Trend Plus (GT-S7580).

Running 'adb root' gives me the same 'adbd cannot run as root in production builds' error.

For devices that have Developer Options -> Root access, choose "ADB only" to provide adb root access to the device (as suggested by NgaNguyenDuy).

Then try to run the command as per the solution at Launch a script as root through ADB. In my case, I just wanted to run the 'netcfg rndis0 dhcp' command, and I did it this way:

adb shell "su -c netcfg rndis0 dhcp"

Please check whether you are making any mistakes while running it this way.

If it still does not work, check whether you rooted the device correctly. If still no luck, try installing a custom ROM such as Cyanogen Mod in order for 'adb root' to work.

Share:
389,639

Related videos on Youtube

rumit patel
Author by

rumit patel

Updated on March 18, 2021

Comments

  • rumit patel
    rumit patel about 3 years

    I rooted my unlocked Galaxy S3 (SGH-T999)

    Now, I'm trying to run adb root from Windows Command Prompt, however, I'm getting adbd cannot run as root in production builds error. So, the very first thing I checked was whether my phone was really rooted?

    So I tried the following:

    Open Command prompt

    $adb devices // lists my device
    $adb shell //goes to shell
    $su // opens a 'SuperSu' prompt on my phone and I 'Grant' permission
    # // Before following the rooting instructions, I was getting 'no su command found' in the previous step. So, I believe my phone is ROOTED. **Correct me if I'm wrong.**
    

    However, when I do adb root, I get adbd cannot run as root in production builds error. So, I thought, I might have to do some additional stuff beyond what I did above. I tried all the solutions in the following SO questions:

    None of the above worked for me. All they do is give the ROOT access INSIDE of SHELL. I want adb root to work so that I can execute various adb commands WITHOUT going into shell.

    • drdrej
      drdrej over 8 years
      doesn't work in android > 4.3. su is missing.
  • Alkanshel
    Alkanshel over 7 years
    I don't see a "Root access" option in dev options.
  • NgaNguyenDuy
    NgaNguyenDuy over 7 years
    @Amalgovinus I think it depends on which room you are using. :)
  • Syed Waqas Bukhary
    Syed Waqas Bukhary over 5 years
    Where can I get compiled executable of the above?
  • Sanjay
    Sanjay over 5 years
    how can we differentiate both emulator?
  • Pythagoras of Samos
    Pythagoras of Samos about 5 years
    I add the new values for ro.debuggable and ro.secure to the files you've specified, but they still get overwritten on every reboot and the changes don't have any effect.
  • Lobster Fighter
    Lobster Fighter about 5 years
    @NgaNguyenDuy Can you please identify which rom you are using?
  • Andrew Steinmetz
    Andrew Steinmetz over 4 years
    @Sanjay when you open up the Android Virtual Device Manager, you should see a tab for Play Store and you want to make sure there is no play store icon present on the device you are trying to root.
  • trigster
    trigster over 4 years
    2020, this helped me but I do need a way to do it on devices with play store enabled without a rooted phone but not sure if it is posible
  • Sachin G
    Sachin G about 4 years
    On Mac OS, I'm getting "/system/bin/sh: su: not found" error. Any suggestions please?
  • gkpln3
    gkpln3 almost 4 years
    @SachinG Maybe you used the wrong type of quotes? try running this adb shell "su -c whoami"
  • Sachin G
    Sachin G almost 4 years
    @gkpln3 Still getting the same error. /system/bin/sh: su: not found
  • JDOaktown
    JDOaktown about 3 years
    My tablet doesn't have vi or edlin. How do I edit these .prop files? And the file itself doesn't give any write access to anyone including root.
  • JDOaktown
    JDOaktown about 3 years
    I was able to edit the build.prop file and it worked! Thanks. See my answer below crediting Alex P.