使用 udev 规则在没有 sudo 的情况下调用 libusb [英] libusb calls without sudo using udev-rules

查看:31
本文介绍了使用 udev 规则在没有 sudo 的情况下调用 libusb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在 Kubuntu 16.04 64 位上测试.我有一个应用程序,其来源不在我的控制之下.它使用了一些 libusb 调用,这些调用以例如:

Tested on Kubuntu 16.04 64 bit only. I have an application which source is not under my control. It uses some libusb calls which ends up in e.g.:

libusb: error [_get_usbfs_fd] libusb couldn't open USB device /dev/bus/usb/001/031: Permission denied
libusb: error [_get_usbfs_fd] libusb requires write access to USB device nodes.                                   

以 root 身份运行上述应用程序时,它按预期工作.当我更改相关文件的权限时:

When running the above mentioned application as root, it works as expected. When I change the permissions of the regarding file like:

sudo chmod a+w /dev/bus/usb/001/031

然后应用程序将使用标准用户权限(直到我断开/重新连接我的 USB 设备).

then the application will work with standard user rights (until I disconnect / reconnect my usb device).

现在我正在寻找一种方法,例如每次插入特定USB设备时自动执行chmod a+w.是否可以通过编写特定的 udev 规则来实现?

Now I'm looking for a way, to e.g. automatically execute the chmod a+w each time when the specific usb device is plugged in. Might this be possible by writing a specific udev rule?

也许 libusb 调用的其他解决方案没有 root 权限?

Maybe other solutions the libusb calls without root rights?

解决方案:根据 David Grayson 的回答,我现在在我的规则文件中添加了带有 SUBSYSTEM=="usb" 的附加行.我的规则文件现在最终看起来像这样:

Solution: Based upon David Grayson's answer, I'd now added an additional line with SUBSYSTEM=="usb" to my rule file. My rules file now finally looks like this:

SUBSYSTEM=="tty", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", MODE="0666"

推荐答案

我建议你在 /etc/udev/rules.d 中添加一个名为 usb.rules 的新文件代码>.它应该有以下内容:

I suggest that you add a new file in /etc/udev/rules.d named usb.rules. It should have the following contents:

SUBSYSTEM=="usb", MODE="0666"

这将使所有用户都可以读写所有 USB 设备.

This will make all USB devices readable and writable by all users.

您还可以使用 Ignacio 的回答中提到的 idVendoridProduct 属性将其缩小到特定的 USB 设备.

You could also narrow it down to specific USB devices using idVendor and idProduct attributes mentioned in Ignacio's answer.

这篇关于使用 udev 规则在没有 sudo 的情况下调用 libusb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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