拒绝非 root 用户使用 USB 设备的权限

拒绝非 root 用户使用 USB 设备的权限

我在让 Arduino Tiny AVR 编程器(又名 PMG-11801)在我的 Ubuntu 18.04 笔记本电脑上运行时遇到了很多困难。这是一个 Arduino 设备,可以在 Arduino IDE 中对 ATTiny85 芯片进行编程。

我读过来自不同地方的几篇论坛帖子,并尝试了一种解决方案,该解决方案对其他人似乎有效,但对我却不起作用。以下是我所做的。

mmachenry$ lsusb
... other devices ...
Bus 001 Device 013: ID 1781:0c9f Multiple Vendors USBtiny
... other devices ...

我记下 1781:0c9f 作为下一步的供应商和产品 ID。

从我找到的各种网页来看,似乎我需要在 /etc/udev/rules.d 中添加一个条目,以允许非 root 用户使用该设备。我添加了它,它看起来像这样:

mmachenry$ cat /etc/udev/rules.d/99-USBtiny.rules 
SUBSYSTEM=="usb", ATTR{idVendor}=="1781", ATTR{idProduct}=="0c9f", GROUP="adm", MODE="0666"

另请注意,我在正确的组中。

mmachenry$ groups
mmachenry adm dialout cdrom sudo dip plugdev docker lpadmin sambashare

为了使其生效,在创建规则文件后立即运行这些文件。

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

根据 Norbert 的评论要求,我对我的用户组进行了健全性检查,但似乎没有任何问题,因为没有输出。

mmachenry@mmachenry-laptop:~$ sudo update-passwd --sanity-check --verbose

但是当我运行 avrdude 时,我的权限被拒绝。

mmachenry$ hardware/tools/avr/bin/avrdude -C/home/mmachenry/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/tools/avr/etc/avrdude.conf -vv -pattiny85 -cusbtiny

avrdude: Version 6.3, compiled on Jan 17 2017 at 11:00:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/mmachenry/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/home/mmachenry/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: 001:013
avrdude: Warning: cannot open USB device: Permission denied
avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)

avrdude done.  Thank you.

但是,当使用 sudo 运行命令时,我得到了非常不同的积极输出。

sudo hardware/tools/avr/bin/avrdude -C/home/mmachenry/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/tools/avr/etc/avrdude.conf -vv -pattiny85 -cusbtiny

avrdude: Version 6.3, compiled on Jan 17 2017 at 11:00:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/mmachenry/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/home/mmachenry/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: 001:013
         AVR Part                      : ATtiny85
         Chip Erase delay              : 400000 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    12     4    0 no        512    4      0  4000  4500 0xff 0xff
           flash         65     6    32    0 yes      8192   64    128 30000 30000 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
CMD: [ac 53 00 00] [ac 52 53 00]
avrdude: AVR device initialized and ready to accept instructions

Reading |                                                    | 0% 0.00sCMD: [30 00 00 00] [00 30 00 1e]
CMD: [30 00 01 00] [00 30 00 93]
Reading | #################                                  | 33% 0.00sCMD: [30 00 02 00] [00 30 00 0b]
Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e930b (probably t85)
CMD: [50 00 00 00] [00 50 00 e2]
CMD: [50 00 00 00] [00 50 00 e2]
CMD: [50 00 00 00] [00 50 00 e2]
CMD: [58 08 00 00] [00 58 08 df]
CMD: [58 08 00 00] [00 58 08 df]
CMD: [58 08 00 00] [00 58 08 df]
avrdude: safemode: hfuse reads as DF
CMD: [50 08 00 00] [00 50 08 ff]
CMD: [50 08 00 00] [00 50 08 ff]
CMD: [50 08 00 00] [00 50 08 ff]
avrdude: safemode: efuse reads as FF

CMD: [50 00 00 00] [00 50 00 e2]
CMD: [50 00 00 00] [00 50 00 e2]
CMD: [50 00 00 00] [00 50 00 e2]
CMD: [58 08 00 00] [00 58 08 df]
CMD: [58 08 00 00] [00 58 08 df]
CMD: [58 08 00 00] [00 58 08 df]
avrdude: safemode: hfuse reads as DF
CMD: [50 08 00 00] [00 50 08 ff]
CMD: [50 08 00 00] [00 50 08 ff]
CMD: [50 08 00 00] [00 50 08 ff]
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:DF, L:E2)

avrdude done.  Thank you.

在 Arduino IDE 中运行此程序具有相同的效果。作为普通用户,我被拒绝权限。当我以 root 身份运行 IDE 时,它可以完全运行并将我的程序上传到 Arduino。请注意,由于它是 usbtinyISP,因此该设备被识别为 USB 设备,而不是像某些 Arduino 那样的串行设备。

为什么普通用户访问该设备的权限仍然被拒绝?

谢谢。

答案1

  1. 确保您的 udev 规则正确:

    SUBSYSTEM=="usb", ATTRS{product}=="USBtiny", ATTRS{idProduct}=="0c9f", ATTRS{idVendor}=="1781", MODE="0660", GROUP="dialout"
    
  2. 确保刷新 udev:

    sudo udevadm control --reload-rules && sudo udevadm trigger
    
  3. 确保拔下并重新插入 USB 设备!

最后一个我花了一些时间才弄清楚!

相关内容