可以访问Linux(libusb-1.0)上的USB设备吗? [英] Get access to USB device on Linux (libusb-1.0)?

查看:283
本文介绍了可以访问Linux(libusb-1.0)上的USB设备吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个小程序,用于在Linux上使用libusb-1.0与特定的USB HID产品(由供应商和产品ID标识)进行通信.现在,我必须以root用户身份运行该程序,因为"libusb需要对USB设备节点的写访问权限".有没有一种方法可以更改我需要的设备上的权限,从而无需以root用户身份运行程序?

I am writing a small program to communicate with a specific USB HID product (identified by vendor and product IDs), using libusb-1.0 on Linux. Right now, I have to run the program as root because "libusb requires write access to USB device nodes". Is there a way to change the permissions on the device I need so that I don't need to run my program as root?

推荐答案

在现代Linux系统上,udevd(man 7 udev)在插入USB设备时会为其创建设备节点.添加与udev规则匹配的udev规则您的设备(例如,您可以通过USB供应商和产品ID进行匹配),并设置设备节点的OWNER/GROUP/MODE.

On modern Linux systems, udevd (man 7 udev) creates the device nodes for USB devices when they're plugged in. Add a udev rule that matches your device (eg. you could match by USB Vendor and Product IDs), and sets the OWNER / GROUP / MODE of the device node.

最好的方法可能是为应该能够访问设备的用户创建一个新组,然后在udev规则中将其设置为组所有者.您可能还需要使用MODE来确保它具有组读取/写入权限.例如.您的规则可能类似于:

The best approach is probably to create a new group for users who should be able to access the device, then set that as the group owner in the udev rule. You may also need to use MODE to ensure that it has group read/write permissions. Eg. your rule will probably look something like:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="ffee", ATTRS{idProduct}=="5a5a", MODE="0660", GROUP="foobar"

这篇关于可以访问Linux(libusb-1.0)上的USB设备吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆