简体   繁体   中英

Udev rules are not working for libusb on Ubuntu 12.04

I'm on Ubuntu 12.04.5 LTS, x86_64.

I've a usb device that uses libusb to communicate with the computer. Once I plug it into the computer and run the communication program I get the following error:

libusb couldn't open USB device /dev/bus/usb/008/004: Permission denied.
libusb requires write access to USB device nodes.
libusb failed to find the Optotrak USB device.  Are you sure you have set the udev permissions correctly?

So if I chmod the /dev/bus/usb/008/004 as follows:

sudo chmod 777 /dev/bus/usb/008/004

and run the communication program again, then the device works perfectly. The problem is that every time I plug the device, the last number changes, so I should have to chmod every time the usb bus, but since not all users know the administrator password this is a problem.

So the manufacturer suggest to edit the udev rules as follows. Create a 12-ndi-rules inside /etc/udev/rules.d :

BUS=="usb", SYSFS{idVendor}=="0403", SYSFS{idProduct}=="da77", GROUP="plugdev"

(I've checked with lsusb that SYSFS are correct)

lsusb 

Bus 008 Device 004: ID 0403:da77 Future Technology Devices International, Ltd 

and then reload the rules:

sudo udevadm control --reload-rules

but still the permissions for bus 008/004 are not correctly set.

How do I make these rules permament at every reboot? I would also like to get make them permanent also if I change the port of the usb device.

OK here are all the steps to get this to work. I had problems with all responses I found online, bits and pieces everywhere without any certain order and no single working solution, (running Android Studio, Jmonkey 3D, and Ubuntu 14.04)

If adb devices shows android device as ????????? (no permissions) follow these instructions:

1) create file /etc/udev/rules.d/51-android.rules

sudo gedit /etc/udev/rules.d/51-android.rules

2) copy and paste contents below:

SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="0e79", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="413c", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="091e", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="24e3", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="2116", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="0482", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="17ef", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0666", GROUP="plugdev"    
SUBSYSTEM=="usb", ATTRS{idVendor}=="0409", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="2080", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="0955", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="2257", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="10a9", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="1d4d", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="0471", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="04da", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="05c6", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="1f53", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="04dd", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="0930", MODE="0666", GROUP="plugdev"  
SUBSYSTEM=="usb", ATTRS{idVendor}=="19d2", MODE="0666", GROUP="plugdev" 

3) Run the following command to change file permissions:

sudo chmod a+r /etc/udev/rules.d/51-android.rules

4) connect your phone via usb and run the following command:

lsusb

Look for your device(s) Example (Nexus 5):

Bus 003 Device 074: ID 18d1 :4ee7 Google Inc.

For Nexus 5 , Vendor ID is 18d1 , mine is on Bus " 003 "

5) Now reload the rules with the following commands:

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

6) Verify device is now allowing plugdev user group access

ls -l /dev/bus/usb/<bus number from step 4>

Example:

ls -l /dev/bus/usb/003

crw-rw-rw- 1 root plugdev 189, 329 Jul  3 18:23 074

7) Run adb devices to confirm permissions are correct and enjoy!

Note: if you haven't created the plugdev group and added your user name to it (if permission denied prepend "sudo" following commands):

1) add plugdev group:

groupadd plugdev

2) add your username to plugdev group (useradd -G {group-name} username):

useradd -G plugdev billy

3) restart udev (you may need to log off and log back in to update user group):

sudo service udev restart

Unless you have a really old udev, the rule is wrong, it should be :

SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="da77", GROUP="plugdev"

Putting the rule in a file in /etc/udev/rules.d/ is the correct way to make it permanent.

Other things you can put in a rule file are in the man page .

I am also working in more or less the same thing and to do the reload I have the same problem using that function, but if you were to use

udevadm trigger

It will actually reload the rules Also, I don't know if you already did so, I think you have to add the users to the group you created

Sometimes, the user is not part of the group that was granted access by the udev rules. To add the (existing) user, to (existing) group plugdev, you should do this:

sudo usermod -a -G groupName userName

SUBSYSTEM=="usb", ATTR{idVendor}=="0403", ATTR{idProduct}=="da77", GROUP="plugdev"

Putting the rule in a file in /etc/udev/rules.d/ is the correct way to make it permanent.

Only it helped me to run Qt Creator with permission for USB exchange (dev/usb/hiddev0) under Debian 11 with LXQt!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM