Linux Android Debug Bridge (adb) 设备 - 无权限

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

Android Debug Bridge (adb) device - no permissions

androidlinuxdebuggingadb

提问by Kristopher

I have a problem connecting HTC Wildfire A3333 in debugging mode with my Fedora Linux 17. Adb says:

我在调试模式下将 HTC Wildfire A3333 与 Fedora Linux 17 连接时出现问题。Adb 说:

./adb devices
List of devices attached 
????????????    no permissions

my udev rules (first rule for Samsung which works just fine and second for HTC which is not):

我的 udev 规则(三星的第一条规则很好用,HTC 的第二条规则不是):

SUBSYSTEM=="usb",SYSFS{idVendor}=="04e8",SYMLINK+="android_adb",MODE="0666",GROUP="plugdev" 
SUBSYSTEM=="usb",SYSFS{idVendor}=="0bb4",SYMLINK+="android_adb",MODE="0666",GROUP="plugdev"

For Samsung devices everything's okay:

对于三星设备,一切正常:

 ./adb devices
List of devices attached 
00198a9422618e  device

I have been trying all of the answers given in a simmilar thread wthout any luck: Using HTC wildfire for android development

我一直在尝试在一个类似的线程中给出的所有答案,但没有任何运气:Using HTC wildfire for android development

采纳答案by Kristopher

The cause of that problem has to do with system permissions (thanks @?IsaacCisneros for this suggestion). Somehow HTC Wildfire (and maybe the others) need something more from the system than Samsung devices. Simple solution is to run Eclipse as a root, but this is not very comfortable with non-sudo Linux systems like Fedora.

该问题的原因与系统权限有关(感谢@?IsaacCisneros 提供此建议)。不知何故,HTC Wildfire(也许还有其他)需要系统提供的东西比三星设备更多。简单的解决方案是以 root 身份运行 Eclipse,但这对于非 sudo Linux 系统(如 Fedora)来说不是很舒服。

I've found another way of achieving the same goal, which seems to be more user friendly and is lesser security hole then running entire IDE with super user privileges. Mind this is still only a workaround of the problem. System root usage should be minimalized only to administrative tasks, and “adb” was designed to work with normal user account without SUID. Despite of the fact that the proper setting of SUID is quite secure, every single permission increase is a potential system security hole.

我找到了实现相同目标的另一种方法,它似乎对用户更友好,并且比以超级用户权限运行整个 IDE 的安全漏洞更小。请注意,这仍然只是问题的解决方法。系统 root 的使用应仅用于管理任务,并且“adb”旨在与没有 SUID 的普通用户帐户一起使用。尽管正确设置 SUID 是非常安全的,但每一次权限的增加都是一个潜在的系统安全漏洞。

1.Setting ownership of the adb binary (owner – root, owner group - user_group):

1.设置adb二进制文件的所有权(所有者-root,所有者组-user_group):

chown root:user_group adb

chown root:user_group adb

2.Setting permissions with SUID:

2.设置SUID权限:

chmod 4550 adb

chmod 4550 adb

This should result something similar to this (ls -llh):

这应该会产生与此类似的结果 (ls -llh):

-r-sr-x---. 1 root user_name 1.2M Jan 8 11:42 adb

-r-sr-x---. 1 root user_name 1.2M Jan 8 11:42 adb

After that you will be able to run adb as a root, event though you'll be using your normal user account. You can run Eclipse as a normal user and your HTC should be discovered properly.

之后,您将能够以 root 身份运行 adb,尽管您将使用普通用户帐户。您可以以普通用户身份运行 Eclipse,您的 HTC 应该会被正确发现。

./adb devices 
List of devices attached 
HT0BPPY15230    device 

回答by Leon

I just had this problem myself under Debian Wheezy. I restarted the adb daemon with sudo:

我自己刚刚在 Debian Wheezy 下遇到了这个问题。我用 sudo 重新启动了 adb 守护进程:

sudo ./adb kill-server
sudo ./adb start-server
sudo ./adb devices

Everything is working :)

一切正常:)

回答by Chan

under ubuntu 12.04, eclipse juno. I face the same issue. This what I found on Yi Yu Blog

在 ubuntu 12.04 下,eclipse juno。我面临同样的问题。这是我在易宇博客上发现的

The solution is same as same as Leon

解决方案与Leon相同

sudo -s
adb kill-server
adb start-server
adb devices

回答by MikeW

I'll prepend this postscript here at the top so it won't get lost in my earlier explanation.

我将把这个附言放在顶部,这样它就不会在我之前的解释中丢失。

I can reliably produce and resolve the no-permissions problem by simply changing the USB connection type from Camera (PTP) to Media device (MTP). The camera mode allows debugging; the media mode causes the no-permissions response in ADB.

我可以通过简单地将 USB 连接类型从相机 (PTP) 更改为媒体设备 (MTP) 来可靠地生成和解决无权限问题。相机模式允许调试;媒体模式会导致 ADB 中的无权限响应。

The reasoning seems pretty evident after reflecting on that for a moment. Unsecured content on the device would be made accessible by the debugger in media server mode.

思考片刻后,推理似乎很明显。调试器可以在媒体服务器模式下访问设备上不安全的内容。

===========

============

The device is unpermissioned until you accept the RSA encryption warning on the debugged device. At some point after connecting, the device will ask to accept the debugging connection. It's a minimal security protocol that ensures you can access the device beyond the initial swipe lock. Developer mode needs to be enabled, I believe.

在您接受调试设备上的 RSA 加密警告之前,该设备是未经许可的。在连接后的某个时刻,设备会要求接受调试连接。这是一个最低限度的安全协议,可确保您可以在初始滑动锁定之后访问设备。我相信需要启用开发人员模式。

The "no permissions" flag is actually a good first indicator that adb recognizes the device as a valid debugging target. Notice that it doesn't list your other USB devices.

“无权限”标志实际上是 adb 将设备识别为有效调试目标的一个很好的第一个指标。请注意,它没有列出您的其他 USB 设备。

Details at the following and related pages.

详情请见以下及相关页面。

http://developer.android.com/tools/device.html

http://developer.android.com/tools/device.html

回答by Robert Siemer

...the OP's own answer is wrongin so far, that there are no “special system permissions”. – The “no permission” problem boils down to ... no permissions.

...到目前为止,OP 自己的答案是错误的,即没有“特殊系统权限”。– “无权限”问题归结为...没有权限。

Unfortunately it is not easy to debug, because adb makes it a secret which device it tries to access! On Linux, it tries to open the “USB serial converter” device of the phone, which is e.g. /dev/bus/usb/001/115 (your bus number and device address will vary). This is sometimes linked and used from /dev/android_adb.

不幸的是,调试并不容易,因为 adb 使它成为它尝试访问的设备的秘密!在Linux上,它会尝试打开手机的“USB串口转换器”设备,例如/dev/bus/usb/001/115(你的总线号和设备地址会有所不同)。这有时从 /dev/android_adb 链接和使用。

lsusbwill help to find bus number and device address. Beware that the device address will change for sure if you re-plug, as might the bus number if the port gets confused about which speed to use (e.g. one physical port ends up on one logical bus or another).

lsusb将有助于查找总线编号和设备地址。请注意,如果您重新插入,设备地址肯定会改变,如果端口对使用哪种速度感到困惑(例如,一个物理端口最终位于一个逻辑总线或另一个逻辑总线上),则总线编号也可能会改变。

An lsusb-line looks similar to this: Bus 001 Device 115: ID 4321:fedc bla bla bla

一条 lsusb 线看起来类似于:Bus 001 Device 115: ID 4321:fedc bla bla bla

lsusb -vmight help you to find the device if the “bla bla bla” is not hint enough (sometimes it does neither contain the manufacturer, nor the model of the phone).

lsusb -v如果“bla bla bla”不够提示(有时它既不包含制造商,也不包含手机型号),可能会帮助您找到设备。

Once you know the device, check with your own eyes that ls -a /dev/bus/usb/001/115is really accessible for the user in question! Then check that it works with chmodand fix your udev setup.

一旦您了解了该设备,请用您自己的眼睛检查ls -a /dev/bus/usb/001/115相关用户是否真正可以访问该设备!然后检查它是否适用chmod并修复您的 udev 设置。

PS1: /dev/android_adb can only point to one device, so make sure it does what you want.

PS1:/dev/android_adb 只能指向一个设备,所以请确保它做你想要的。

PS2: Unrelated to this question, but less well known: adb has a fixed list of vendor ids it goes through. This list can be extended from ~/.android/adb_usb.ini, which should contain 0x4321 (if we follow my example lsusb line from above). – Not needed here, as you don't even get a “no permissions” if the vendor id is not known.

PS2:与此问题无关,但鲜为人知:adb 有一个固定的供应商 ID 列表。这个列表可以从 ~/.android/adb_usb.ini 扩展,它应该包含 0x4321(如果我们按照上面的示例 lsusb 行)。– 此处不需要,因为如果不知道供应商 ID,您甚至不会获得“无权限”。

回答by Micha?l Witrant

You udev rule seems wrong. I used this and it worked:

你的 udev 规则似乎是错误的。我使用了这个并且它有效:

SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"

(ATTRinstead of SYSFS)

(ATTR而不是SYSFS)

回答by user149408

Another possible source of this issue is USB tethering. If you have used USB tethering, turn it off, then unplug the device from USB, plug it back in, then do

此问题的另一个可能来源是 USB 网络共享。如果您使用过 USB 网络共享,请将其关闭,然后从 USB 上拔下设备,重新插入,然后执行

adb kill-server
adb devices

That did the trick in my case (Ubuntu 12.04, Nexus S, SDK in home dir, never needed root to get it running). Depending on your device, you may need to run adb devicesas root, though.

这在我的情况下成功了(Ubuntu 12.04、Nexus S、家庭目录中的 SDK,从来不需要 root 来运行它)。不过,根据您的设备,您可能需要以adb devicesroot身份运行。

回答by Roger Lipscombe

I have a similar problem:

我有一个类似的问题:

$ adb devices
List of devices attached 
4df15d6e02a55f15    device
????????????    no permissions

Investigation

调查

If I run lsusb, I can see which devices I have connected, and where:

如果我运行lsusb,我可以看到我连接了哪些设备,以及在哪里:

$ lsusb
...
Bus 002 Device 050: ID 04e8:6860 Samsung Electronics Co., Ltd GT-I9100 Phone ...
Bus 002 Device 049: ID 18d1:4e42 Google Inc. 

This is showing my Samsung Galaxy S3and my Nexus 7 (2012)connected.

这显示了我的Samsung Galaxy S3和我的Nexus 7 (2012) 已连接。

Checking the permissions on those:

检查这些权限:

$ ls -l /dev/bus/usb/002/{049,050}
crw-rw-r--  1 root root    189, 176 Oct 10 10:09 /dev/bus/usb/002/049
crw-rw-r--+ 1 root plugdev 189, 177 Oct 10 10:12 /dev/bus/usb/002/050

Wait. What? Where did that "plugdev" group come from?

等待。什么?“plugdev”小组从何而来?

$ cd /lib/udev/rules.d/
$ grep -R "6860.*plugdev" .
./40-libgphoto2-2.rules:ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="6860", \
  ENV{ID_GPHOTO2}="1", ENV{GPHOTO2_DRIVER}="proprietary", \
  ENV{ID_MEDIA_PLAYER}="1", MODE="0664", GROUP="plugdev"
./40-libgphoto2-2.rules:ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="6860", \
  ENV{ID_GPHOTO2}="1", ENV{GPHOTO2_DRIVER}="proprietary", \
  ENV{ID_MEDIA_PLAYER}="1", MODE="0664", GROUP="plugdev"

(I've wrapped those lines)

(我已经把这些行包起来了)

Note the GROUP="plugdev"lines. Also note that this doesn't work for the other device ID:

注意GROUP="plugdev"线条。另请注意,这不适用于其他设备 ID:

$ grep -Ri "4e42.*plugdev" .

(nothing is returned)

(什么都不返回)

Fixing it

修复它

OK. So what's the fix?

好的。那么有什么解决办法呢?

Add a rule

添加规则

Create a file /etc/udev/rules.d/99-adb.rulescontaining the following line:

创建一个/etc/udev/rules.d/99-adb.rules包含以下行的文件:

ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4e42", ENV{ID_GPHOTO2}="1",
  ENV{GPHOTO2_DRIVER}="proprietary", ENV{ID_MEDIA_PLAYER}="1",
  MODE="0664", GROUP="plugdev"

This should be a single line, I've wrapped it here for readability

这应该是一行,为了便于阅读,我把它包装在这里

Restart udev

重启udev

$ sudo udevadm control --reload-rules
$ sudo service udev restart

That's it

就是这样

Unplug/replug your device.

拔下/重新插入您的设备。

Try it

尝试一下

$ adb devices
List of devices attached 
4df15d6e02a55f15    device
015d2109ce67fa0c    device

回答by Overloaded_Operator

The answer is weaved amongst the various posts here, I'll so my best, but it looks like a really simple and obvious reason.

答案交织在这里的各种帖子中,我会尽力而为,但这看起来是一个非常简单而明显的原因。

1) is that there usually is a "user" variable in the udev rule some thing like USER="your_user" probably right after the GROUP="plugdev"

1) 是在 udev 规则中通常有一个“用户”变量,比如 USER="your_user" 可能就在 GROUP="plugdev" 之后

2) You need to use the correct SYSFS{idVendor}==”####″ and SYSFS{idProduct}=="####" values for your device/s. If you have devices from more than one manufacture, say like one from Samsung and one from HTC, then you need to have an entry(rule) for each vendor, not an entry for each device but for each different vendor you will use, so you need an entry for HTC and Samsung. It looks like you have your entry for Samsung now you need another. Remember the USER="your_user". Use 'lsusb' like Robert Seimer suggests to find the idVendor and idProduct, they are usually some numbers and letters in this format X#X#:#X#X I think the first one is the idVendor and the second idProduct but your going to need to do this for each brand of phone/tablet you have.

2) 您需要为您的设备使用正确的 SYSFS{idVendor}==”####″ 和 SYSFS{idProduct}==”####” 值。如果您拥有来自多个制造商的设备,例如一个来自三星,一个来自 HTC,那么您需要为每个供应商设置一个条目(规则),而不是每个设备的条目,而是您将使用的每个不同供应商的条目,因此你需要一个 HTC 和三星的入口。看起来您已经获得了三星的参赛资格,现在您需要另一个参赛资格。记住 USER="your_user"。使用 Robert Seimer 建议的“lsusb”来查找 idVendor 和 idProduct,它们通常是这种格式的一些数字和字母 X#X#:#X#XI 认为第一个是 idVendor,第二个是 idProduct 但你需要为您拥有的每个品牌的手机/平板电脑执行此操作。

3) I havent figured out how 51-adb.rules and 99-adb.rules are different or why.

3) 我还没有弄清楚 51-adb.rules 和 99-adb.rules 有什么不同或为什么不同。

4) maybe try adding "plugdev" group to your user with "usermod -a -G plugdev your_user", Try that at your own risk, though I don't thinks it anyriskier than launching a gui as root but I believe if necessary you should at least use "gksudo eclipse" instead.

4)也许可以尝试使用“usermod -a -G plugdev your_user”向您的用户添加“plugdev”组,请自行承担风险,尽管我认为这不会比以root身份启动gui风险更大,但我相信如果有必要的话至少应该使用“gksudo eclipse”代替。

I hope that helped clearify some things, the udev rules syntax is a bit of a mystery to me aswell, but from what I hear it can be different for different systems so try some things out, one ate a time, and note what change works.

我希望这有助于澄清一些事情,udev 规则语法对我来说也有点神秘,但据我所知,不同的系统可能会有所不同,所以尝试一些事情,一次吃一次,并注意哪些更改有效.

回答by Brent Faust

Stephan's answer works (using sudo adb kill-server), but it is temporary. It must be re-issued after every reboot.

Stephan 的回答有效(使用 sudo adb kill-server),但它是暂时的。每次重新启动后必须重新发出。

For a permanent solution, the udev config must be modified:

对于永久解决方案,必须修改 udev 配置:

Witrant's answer is the right idea (copied from the official Android documentation). But it's just a template. If that doesn't work for your device, you need to fill in the correct device ID for your device(s).

Witrant 的答案是正确的想法(从官方 Android 文档中复制)。但这只是一个模板。如果这不适用于您的设备,您需要为您的设备填写正确的设备 ID。

lsusb

lsusb

Bus 001 Device 002: ID 05c6:9025 Qualcomm, Inc.
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
...

Find your android device in the list.

在列表中找到您的 android 设备。

Then use the first half of the ID (4 digits) for the idVendor (the last half is the idProduct, but it is not necessary to get adb working).

然后使用 ID 的前半部分(4 位数字)作为 idVendor(后半部分是 idProduct,但没有必要让 adb 工作)。

sudo vi /etc/udev/rules.d/51-android.rulesand add one rule for each unique idVendor:

sudo vi /etc/udev/rules.d/51-android.rules并为每个唯一的 idVendor 添加一条规则:

SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666", GROUP="plugdev"

It's that simple. You don't need all those other fields given in some of the answers. Save the file.

就这么简单。您不需要某些答案中给出的所有其他字段。保存文件。

Then reboot. The change is permanent. (Roger shows a way to restart udev, if you don't want to reboot).

然后重启。这种变化是永久性的。(如果您不想重新启动,Roger 展示了一种重新启动 udev 的方法)。