如何解决Android ADB主机设备中未经授权的ADB设备?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26213954/
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 11:08:00  来源:igfitidea点击:

How to solve ADB device unauthorized in Android ADB host device?

androidshelladb

提问by Kong Ken

When I'm using a rooted Android device as ADB host to send adb command "adb devices" to Samsung S4, I received device unauthorized error message. However when I tried adb to Samsung Galaxy Nexus, it is working fine. Can anyone advise how to solve my Samsung S4 problem?

当我使用有根的 Android 设备作为 ADB 主机向三星 S4 发送 adb 命令“adb devices”时,我收到设备未经授权的错误消息。但是,当我尝试使用 adb 到 Samsung Galaxy Nexus 时,它运行良好。谁能建议如何解决我的三星 S4 问题?

=========================================
# adb devices
List of devices attached
4d00f9169907301b        unauthorized
=========================================

Thanks in advance.

提前致谢。

Edit:Found that this problem only happened to Android 4.2.2 and above. The following link explained that Google has implemented some new security features for using adb.

编辑:发现这个问题只发生在Android 4.2.2及以上。以下链接解释了 Google 为使用 adb 实施了一些新的安全功能。

http://nelenkov.blogspot.com/2013/02/secure-usb-debugging-in-android-422.html

http://nelenkov.blogspot.com/2013/02/secure-usb-debugging-in-android-422.html

Appreciate if anyone can help on this.

感谢是否有人可以对此提供帮助。

回答by ashoke

  • Get the public key from the client phone (adb host)

    cat /data/.android/adbkey.pub

  • copy the above public key to the target phone's /data/misc/adb/adb_keyslocation. (you may need to stop the adb daemon first with stop adbd)

    cat /data/misc/adb/adb_keys

  • 从客户端手机(亚行主机)获取公钥

    猫 /data/.android/adbkey.pub

  • 将上述公钥复制到目标手机的/data/misc/adb/adb_keys位置。(您可能需要先停止 adb 守护进程stop adbd

    猫 /data/misc/adb/adb_keys

verify both catoutputs match.

验证两个cat输出匹配。

try restarting adb daemon on target start adbdor just reboot them.

尝试在目标上重新启动 adb 守护进程start adbd或只是重新启动它们。

If you are having problems reading or writing to ADB KEYS in above steps, try setting environment variable ADB_KEYS_PATHwith a temporary path (eg: /data/local/tmp). Refer to that link it goes intomore details

如果您在上述步骤中读取或写入 ADB KEYS 时遇到问题,请尝试ADB_KEYS_PATH使用临时路径(例如:)设置环境变量/data/local/tmp。请参阅该链接,了解更多详细信息

    "On the host, the user public/private key pair is automatically generated,
    if it does not exist, when the adb daemon starts and is stored in
    $HOME/.android/adb_key(.pub) or in $ANDROID_SDK_HOME on windows. If needed,
    the ADB_KEYS_PATH env variable may be set to a :-separated (; under
    Windows) list of private keys, e.g. company-wide or vendor keys.

    On the device, vendors public keys are installed at build time in
    /adb_keys. User-installed keys are stored in /data/misc/adb/adb_keys"

回答by Prasanth Louis

Check and uncheck the USB Debugging option in the device. If that doesn't work unplug and plug in the USB a couple of times.

选中和取消选中设备中的 USB 调试选项。如果这不起作用,请拔下并插入 USB 几次。

At some point, the device should show a message box to ask you to authorize the computer. Click yes and then the device will be authorized.

在某些时候,设备应该显示一个消息框,要求您对计算机进行授权。单击是,然后设备将被授权。

回答by kiradotee

If anyone has similar issue of having a phone with a cracked screen and has a need to access adb:

如果有人遇到类似手机屏幕破裂的问题并且需要访问 adb:

  1. Root your phone (mine was already rooted, so I was blessed at least with that).
  1. 扎根你的手机(我的已经扎根了,所以至少我很幸运)。

If you forgot to enable developers mode and your adb isn't running, then do the following:

如果您忘记启用开发人员模式并且您的 adb 未运行,请执行以下操作:

  1. Reboot your phone into recovery.
  2. Connect the phone with a cable.
  3. Open terminal.
  4. If you type adb devicesyou should see the device in the list.
  5. If so, type:

    adb shell mount /system
    abd shell
    
    echo "persist.service.adb.enable=1" >> default.prop 
    echo "persist.service.debuggable=1" >> default.prop
    echo "persist.sys.usb.config=mtp,adb" >> default.prop
    echo "persist.service.adb.enable=1" >> /system/build.prop 
    echo "persist.service.debuggable=1" >> /system/build.prop
    echo "persist.sys.usb.config=mtp,adb" >> /system/build.prop
    
  1. 重启手机进入恢复状态。
  2. 用数据线连接手机。
  3. 打开终端。
  4. 如果您键入,adb devices您应该会在列表中看到该设备。
  5. 如果是这样,请键入:

    adb shell mount /system
    abd shell
    
    echo "persist.service.adb.enable=1" >> default.prop 
    echo "persist.service.debuggable=1" >> default.prop
    echo "persist.sys.usb.config=mtp,adb" >> default.prop
    echo "persist.service.adb.enable=1" >> /system/build.prop 
    echo "persist.service.debuggable=1" >> /system/build.prop
    echo "persist.sys.usb.config=mtp,adb" >> /system/build.prop
    

Now if you are going to reboot into your phone android will tell you "oh your adb is working but please tap on this OK button, so we can trust your PC". And obviously if we can't tap on the phone stay in the recovery mode and do the following (assuming you are not in the adb shell mode, if so first type exit):

现在,如果您要重新启动手机,android 会告诉您“哦,您的 adb 正在运行,但请点击此确定按钮,以便我们可以信任您的 PC”。显然,如果我们无法点击手机,请保持在恢复模式并执行以下操作(假设您不在 adb shell 模式下,如果是,请先输入exit):

cd ~/.android
adb push adbkey.pub /data/misc/adb/adb_keys
  1. Hurray, it all should be hunky-dory now! Just reboot the phone and you should be able to access adb when the phone is running:

    adb shell reboot

  1. 万岁,现在这一切都应该是美好的!只需重新启动手机,您应该可以在手机运行时访问 adb:

    adb shell 重启

P.S. Was using OS X and Moto X Style that's with the cracked screen.

PS 使用的是 OS X 和 Moto X Style,屏幕有裂痕。

回答by Tomasz Szuba

Have you tried

你有没有尝试过

adb kill-server
adb shell

Sometimes adb gets stuck and first killing adb server and then starting some command forces authorization window to pop-up.

有时 adb 卡住,先杀死 adb 服务器,然后启动一些命令强制弹出授权窗口。

Also please check adb client version on your phone. THis feature is supported from adb 1.0.31 as far as I remember.

另请检查您手机上的 adb 客户端版本。据我所知,adb 1.0.31 支持此功能。

回答by Karthik Sagar

Experience With: ASUS ZENFONE

使用经验:华硕ZENFONE

If at all you have faced Missing Driver for Asus Zenfones Follow This Link (http://donandroid.com/how-to-install-adb-interface-drivers-windows-7-xp-vista-623)

如果您遇到了 Asus Zenfones 驱动程序丢失的问题,请点击此链接(http://donandroid.com/how-to-install-adb-interface-drivers-windows-7-xp-vista-623

I tried with

我试过

1) Killing and starting adb server at adb cmd.

1) 在 adb cmd 中杀死并启动 adb 服务器。

2) Switching Usb Debugging on and Off and ...

2) 打开和关闭 USB 调试和...

This is What WORKED with me.

这就是对我有用的东西。

Step 1:Remove Connection with Device and Close Eclipse

步骤 1:删除与设备的连接并关闭 Eclipse

Step 2:Navigate to C:/Users/User_name/.android/

第 2 步:导航到 C:/Users/User_name/.android/

Step 3:You Will Find adb_key

第 3 步:您将找到 adb_key

Step 4:Just delete it.

第 4 步:只需删除它。

Step 5.Connect again and System will ask you Again.

第 5 步。再次连接,系统将再次询问您。

Step 6.Ask Device to remember RSA Key when it Prompts. I think its done.

步骤 6 .要求设备在提示时记住 RSA 密钥。我认为它完成了。

If you Face The Same Problem after couple of days, just disable and enable USB debugging

如果几天后您遇到同样的问题,只需禁用并启用 USB 调试

回答by Mritunjay Upadhyay

Try this steps:

试试这个步骤:

  1. unplug device
  2. adb kill-server
  3. adb start-server
  4. plug device
  1. 拔掉设备
  2. adb 杀死服务器
  3. adb 启动服务器
  4. 插头装置

You need to allow Allow USB debugging in your device when popup.

您需要在弹出时允许在您的设备中允许 USB 调试。

回答by cweiske

For unknown reasons, I only had ~/.android/adbkey, but not ~/.android/adbkey.pub.

由于未知的原因,我只有~/.android/adbkey,但没有~/.android/adbkey.pub

I guess that adbwas unable to push the public key to the device, and thus the device could never show the authorization dialog.

我猜这adb无法将公钥推送到设备,因此设备永远无法显示授权对话框。

After killing the adb server, removing the adbkeyfile and starting adbagain, the authorization dialog popped up on the phone.

杀死adb服务器,删除adbkey文件adb重新启动后,手机上弹出授权对话框。

回答by Tan Dat

You need to allow Allow USB debuggingwhen the popup shows up when you first connect to the computer!

Allow USB debugging当您第一次连接到计算机时出现弹出窗口时,您需要允许!

回答by valdetero

For me, the emulator could not have Google Play Services enabled. It could have Google APIs or be x86 or x64 but not google play store.

对我来说,模拟器无法启用 Google Play 服务。它可以有 Google API,也可以是 x86 或 x64,但不能是 google play 商店。

回答by abhishek singh

Delete the folder .androidfrom C:/users/<user name>/.android. It solved the issue for me.

.android从 中删除文件夹C:/users/<user name>/.android。它为我解决了这个问题。