Ubuntu下usb device读写permission denied的解决方法

许多USB硬件第一次插入新电脑时,经常会出现读写权限的问题,提示为

/dev/bus/usb/001/00*: Permission denied

导致这一问题的原因就是设备所属用户和用户组为root而非当前的普通用户。

使用以下命令:

ls -all /dev/bus/usb/001

可以查看用户和用户组

crw-rw-r--  1 root root 189, 0 2012-04-29 19:49 001
crw-rw-r--  1 root root 189, 1 2012-04-29 19:49 002

在此可以发现,设备端口001的用户和用户组都为root。

解决方案通常为两种:

1. 读写权限修改:

    sudo chmod 666 /dev/bus/usb/001/00*

    sudo chown user /dev/bus/usb/001/00*

    sudo chogrp group /dev/bus/usb/001/00*

对于有些硬件,由于每次连接时的端口号都不一样,所以以上方法不适用。

2. 端口分配

    (1) 首先用lsusb命令查看厂家编码和产品编码
Bus 003 Device 002: ID 413c:2003 Dell Computer Corp. Keyboard
Bus 001 Device 007: ID 0403:cb48 Future Technology Devices International, Ltd 
Bus 001 Device 006: ID 0461:4d15 Primax Electronics, Ltd Dell Optical Mouse
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

其中ID后面的就是我们需要的,以第一行为例,产品编码是2003,厂家代码是413c。

然后编辑/etc/udev/rules.d/70-persistent-usb.rules (这个文件可能不存在,可以自己创建。最开始的70可以改,根据自己电脑上的其他文件一致即可), 添加以下文字:

SYSFS{idProduct}=="2003",SYSFS{idVendor}=="413c",MODE="666",OWNER="user",GROUP="group"

有些情况下是:

ATTRS{idProduct}=="2003",ATTRS{idVendor}=="413c",MODE="666",OWNER="user",GROUP="group"

这两个都试试。其中user就是你电脑的用户名,group也可以用user代替。

保存后退出。 此文件需要sudo权限,所以编辑时需要用sudo加在编辑命令前。

重新插入usb设备,并查看用户组和所属用户:

ls -all /dev/bus/usb/001

crw-rw-r--  1 user group 189, 0 2012-04-29 19:49 001
crw-rw-r--  1 root root 189, 1 2012-04-29 19:49 002

这样usb设备001就创建在user的用户和用户组里了。

从新试验读写功能,用户将在普通权限下读写该usb设备。

最后关于这个文件名,在/lib/udev/rules.d/文件夹下有个说明文件readme,内容如下:

The files in this directory are read by udev(7) and used when events
are performed by the kernel.  The udev daemon watches this directory
with inotify so that changes to these files are automatically picked
up, for this reason they must be files and not symlinks to another
location as in the case in Debian.

These are not conffiles.  If you want to override the behaviour, you
can do one of two things:

 1) Write your own rules in /etc/udev/rules.d that assign the name,
    symlinks, permissions, etc. that you want.  Pick a number higher
    than the rules you want to override, and yours will be used.

 2) Copy the file to /etc/udev/rules.d and edit it there; you
    should generally only do this if you want to prevent a program
    from being run.


Files should be named xx-descriptive-name.rules, the xx should be
chosen first according to the following sequence points:

 < 60  rules shipped in packages; these can be overriden by later or
       default rules unless := is used in assignment.

       these cannot access persistent information such as that from
       blkid

 < 70  rules that run helpers such as blkid to populate the udev db

 < 90  rules that run other programs (often using information in the
       udev db)

 >=90  rules that should run last

Common locations for package rules:

 40-xx general rules, setting names and permissions
 65-xx rules to populate the udev db
 85-xx rules to run programs

所以一般那个/etc/udev/rules.d/下的文件可以随意命名,但是开头的数字很重要,代表着加载的优先级。一般和那个文件夹下的其他问价用同样的数字即可;或者使用55,在/lib/udev/rules.d/文件夹内的55-udev-default.rules就是55这个优先级的。所以和这个一致就可以了。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值