Rootop 服务器运维与web架构

通过udev修改/dev/下的设备权限

admin@rd-GMB5188:~$ ll /dev/gpcdrv 
crw------- 1 root root 236, 0 Apr 27 21:00 /dev/gpcdrv

默认此设备只有root账户可以读写,其它账号无法使用,通过udev规则实现自动修改。

# 查看设备属性等信息
root@rd-GMB5188:~# udevadm info -a -n /dev/gpcdrv 

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/virtual/gpcdrv/gpcdrv':
    KERNEL=="gpcdrv"
    SUBSYSTEM=="gpcdrv"
    DRIVER==""
    ATTR{power/async}=="disabled"
    ATTR{power/control}=="auto"
    ATTR{power/runtime_active_kids}=="0"
    ATTR{power/runtime_active_time}=="0"
    ATTR{power/runtime_enabled}=="disabled"
    ATTR{power/runtime_status}=="unsupported"
    ATTR{power/runtime_suspended_time}=="0"
    ATTR{power/runtime_usage}=="0"


# 确定可以通过KERNEL和SUBSYSTEM属性匹配设备进行修改权限。
root@rd-GMB5188:~# cat /etc/udev/rules.d/98-gpcdrv.rules 
KERNEL=="gpcdrv", SUBSYSTEM=="gpcdrv", MODE="0664"

# 重启后再次查看权限
admin@rd-GMB5188:~$ ll /dev/gpcdrv 
crw-rw-r-- 1 root root 235, 0 Apr 27 21:05 /dev/gpcdrv

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/5526.html

作者:Venus

服务器运维与性能优化

评论已关闭。