Android adb shell su 有效,但 adb root 无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25477424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:28:01  来源:igfitidea点击:

adb shell su works but adb root does not

androidshelladbroot

提问by rumit patel

I rooted my unlocked Galaxy S3 (SGH-T999)

我已将解锁的 Galaxy S3 (SGH-T999) 植根

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

现在,我正在尝试adb root从 Windows Command Prompt运行,但是,adbd cannot run as root in production builds出现错误。所以,我检查的第一件事是我的手机是否真的植根了?

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

但是,当我这样做时adb root,我会adbd cannot run as root in production builds出错。所以,我想,除了我上面所做的,我可能还需要做一些额外的事情。我在以下 SO 问题中尝试了所有解决方案:

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

以上都不适合我。他们所做的就是给 SHELL 的 ROOT 访问权限。我想adb root工作,以便我可以在不进入 shell 的情况下执行各种 adb 命令。

回答by NgaNguyenDuy

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

在一些对开发人员友好的 ROM 中,您可以在Settings > Developer option > Root access 中启用Root Access。之后就可以使用了。不幸的是,它不适用于市场上的大多数库存 ROM。adb root

回答by Alex P.

By design adb rootcommand works in development builds only (i.e. engand userdebugwhich have ro.debuggable=1by default). So to enable the adb rootcommand on your otherwise rooteddevice just add the ro.debuggable=1line to one of the following files:

通过设计adb root开发命令只建立(即enguserdebug具有ro.debuggable=1默认情况下)。因此,要adb root在您的其他root设备上启用该命令,只需将该ro.debuggable=1行添加到以下文件之一:

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

If you want adb shellto start as rootby default - then add ro.secure=0as well.

如果您想adb shellroot默认方式启动- 然后添加ro.secure=0

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

或者,您可以使用修改后的adbd二进制文件(不检查ro.debuggable

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

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

回答by Andrew Steinmetz

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 rootwill root the device for you. Hope this helps someone.

我在尝试 root 模拟器时遇到了这个问题,我发现这是因为我正在运行带有 Google Play 的 Nexus 5x 模拟器。创建了一个没有 google play 的不同模拟器,adb root并将为您植根设备。希望这可以帮助某人。

回答by Antony

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

我有一个扎根的三星 Galaxy Trend Plus (GT-S7580)。

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

运行“adb root”给了我同样的“adbd cannot run as root in production builds”错误。

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

对于具有 Developer Options -> Root 访问权限的设备,选择“ADB only”以提供对设备的 adb root 访问权限(如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:

然后尝试根据Launch a script as root through ADB 中的解决方案运行该命令。就我而言,我只想运行“netcfg rndis0 dhcp”命令,我是这样做的:

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 Modin order for 'adb root' to work.

如果它仍然不起作用,请检查您是否正确地植根了设备。如果仍然没有运气,请尝试安装自定义 ROM,例如Cyanogen Mod,以便“adb root”工作。

回答by scrosler

You need to replace the adbd binary in the boot.img/sbin/ folder to one that is su capable. You will also have to make some default.prop edits too.

您需要将 boot.img/sbin/ 文件夹中的 adbd 二进制文件替换为支持 su 的二进制文件。您还必须进行一些 default.prop 编辑。

Samsung seems to make this more difficult than other vendors. I have some adbd binaries you can try but it will require the knowledge of de-compiling and re-compiling the boot.img with the new binary. Also, if you have a locked bootloader... this is not gonna happen.

三星似乎比其他供应商更难做到这一点。我有一些 adbd 二进制文件,您可以尝试,但这需要了解使用新二进制文件反编译和重新编译 boot.img 的知识。另外,如果你有一个锁定的引导加载程序......这不会发生。

Also Chainfire has an app that will grant adbd root permission in the play store: https://play.google.com/store/apps/details?id=eu.chainfire.adbd&hl=en

此外,Chainfire 有一个应用程序可以在 Play 商店中授予 adbd root 权限:https: //play.google.com/store/apps/details?id=eu.chainfire.adbd &hl=en

Lastly, if you are trying to write a windows script with SU permissions you can do this buy using the following command style... However, you will at least need to grant (on the phone) SU permissions the frist time its ran...

最后,如果您尝试编写具有 SU 权限的 Windows 脚本,您可以使用以下命令样式执行此操作...但是,您至少需要在第一次运行时授予(在电话上)SU 权限。 .

adb shell "su -c ls" <-list working directory with su rights. adb shell "su -c echo anytext > /data/test.file"

adb shell "su -c ls" <-list 具有 su 权限的工作目录。adb shell "su -c echo anytext > /data/test.file"

These are just some examples. If you state specifically what you are trying to accomplish I may be able to give more specific advice

这些只是一些例子。如果您具体说明您要完成的工作,我可能会提供更具体的建议

-scosler

-斯科斯勒

回答by Samuel Ivan

I use for enter su mode in abd shell

我用于在 abd shell 中进入 su 模式

adb shell "su"

亚行外壳“su”

回答by cweiske

adbdhas a compilation flag/option to enable root access: ALLOW_ADBD_ROOT=1.

adbd有一个编译标志/选项来启用 root 访问:ALLOW_ADBD_ROOT=1.

Up to Android 9: If adbdon your device is compiled without that flag, it will always drop privileges when starting up and thus "adb root" will not help at all. I had to patch the calls to setuid(), setgid(), setgroups()and the capability drops out of the binary myself to get a permanently rooted adbd on my ebook reader.

直到 Android 9:如果adbd在您的设备上编译时没有该标志,它在启动时总是会放弃特权,因此“adb root”根本无济于事。我不得不打补丁的电话setuid()setgid()setgroups()和能力下降了二进制的自己让我的电子书阅读器永久扎根adbd。

With Android 10 this changed; when the phone/tablet is unlocked (ro.boot.verifiedbootstate == "orange"), then adb root mode is possible in any case.

Android 10 改变了这一点;当手机/平板电脑解锁 ( ro.boot.verifiedbootstate == "orange") 时,无论如何都可以使用 adb root 模式。

回答by warfreak92

If you really need to have ADBrunning as root, the quickest and easiest way is to install Android Custom ROMs and the most popular is CyanogenModfor it has the Root Accessoptions in developer options menu where you can choose to give root access to apps and ADB. I used CM before but since it wasn't developed anymore, I tried looking for some solutions out there. Although CyanogenMod is still a good alternative because it does not have bloatware.

如果你真的需要有ADB作为运行root,最快捷,最简单的方法是安装Android定制ROM和最流行的是CyanogenMod它有Root Access在这里您可以选择提供给root访问权在开发人员选项菜单选项apps and ADB。我之前使用过 CM 但由于它不再开发了,我尝试在那里寻找一些解决方案。尽管 CyanogenMod 仍然是一个不错的选择,因为它没有膨胀软件。

One alternative I found out from a friend is using adbd insecureapp which you could try from here: https://forum.xda-developers.com/showthread.php?t=1687590. In my case, it works perferct with an Android custom kernel, but not with the Android stock ROM (vanilla android only). You may try other alternatives too like modifying boot.imgof the Android ROM.

我从朋友那里发现的另一种选择是使用adbd insecure您可以从这里尝试的应用程序:https: //forum.xda-developers.com/showthread.php?t=1687590。就我而言,它适用于 Android 自定义内核,但不适用于 Android stock ROM(仅限 vanilla android)。您也可以尝试其他替代方法,例如修改boot.imgAndroid ROM。