I'm writing a C/C++ application in NetBeans based on libusb-1.0 on Ubuntu 12.04. I can get basic information from the USB device (for example, the interface description) but I am not able to open the device. The function libusb_open gives me the error:
libusb:error [op_open] libusb couldn't open USB device /dev/bus/usb/002/003: Permission denied.
libusb:error [op_open] libusb requires write access to USB device nodes.
I understand that I need to change the permissions but I don't know how (I am a very basic Linux-user). Thank you!
I think this might be a temporary solution for the problem while Preston's solution would work consistently.
You can figure out which usb port is assigned to your device by invoking ls
command two times(first with device disconnected and second with device connected).
$ ls -l /dev/bus/usb/00*
/dev/bus/usb/001:
total 0
crw-rw-r-- 1 root root 189, 0 1월 10 12:08 001
crw-rw-r-- 1 root root 189, 1 1월 10 12:08 002
/dev/bus/usb/002:
total 0
crw-rw-r-- 1 root root 189, 128 1월 10 12:08 001
crw-rw-r-- 1 root root 189, 129 1월 10 12:08 002
/dev/bus/usb/003:
total 0
crw-rw-r-- 1 root root 189, 256 1월 10 12:08 001
crw-rw-r-- 1 root root 189, 257 1월 10 12:08 002
crw-rw-r-- 1 root root 189, 258 1월 10 12:08 003
crw-rw-r-- 1 root root 189, 259 1월 10 12:08 004
crw-rw-r-- 1 root root 189, 260 1월 10 12:08 005
crw-rw-r-- 1 root root 189, 263 1월 10 15:42 008 <-- this is your device
Let's say /dev/bus/usb/003/008 is your device.
According to the output of ls -l
command, root user(group) has read/write permission on 003/008 port
while other user has only read permission.
crw-rw-r-- 1 root root 189, 263 1월 10 15:42 008
You can allow every user to write on specific device using chmod
command. While using chmod
command, you will need sudo
permission.
$ sudo chmod o+w /dev/bus/usb/003/008
or
$ sudo chmod a+w /dev/bus/usb/003/008
Now if you check the permission of usb, you have to see this output
$ ls -l /dev/bus/usb/003/008
crw-rw-rw- 1 root root 189, 263 1월 10 15:42 /dev/bus/usb/003/008
If you plug the device out from usb port or shut down the system, what you did for your usb port will reset.
You have to repeat step 1,2 again.
This is why I'm saying my solution is temporary(volatile).
I find these two blog articles would be helpful to your understanding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With