如何在 ubuntu 16.04 上永久设置设备读写权限?

如何在 ubuntu 16.04 上永久设置设备读写权限?

我正在使用运行 ubuntu 的嵌入式设备。

通常只有root才有i2c设备的读写权限。

我使用此命令为普通用户(我)添加 i2c r/w 权限:

sudo chmod 777 /dev/i2c-*

但我想制定一个udev规则。我在/etc/udev/rules.d/名为的文件中创建了一个文件60-i2c-tools.rules,并将以下行放入其中。

KERNEL==”i2c-[0-9]*”, MODE=”0660”

但是,当我重新启动设备时,我无法访问 I2C 设备。这些是权限:

crwxrwxrwx 1 root root 89,  0 Aug 10 12:59 /dev/i2c-0
crwxrwxrwx 1 root root 89,  1 Aug 10 12:59 /dev/i2c-1
crw------- 1 root root 89, 10 Aug 10 12:59 /dev/i2c-10
crw------- 1 root root 89, 11 Aug 10 12:59 /dev/i2c-11
crwxrwxrwx 1 root root 89,  2 Aug 10 12:59 /dev/i2c-2
crwxrwxrwx 1 root root 89,  3 Aug 10 12:59 /dev/i2c-3
crw------- 1 root root 89,  4 Aug 10 12:59 /dev/i2c-4
crw------- 1 root root 89,  5 Aug 10 12:59 /dev/i2c-5
crw------- 1 root root 89,  6 Aug 10 12:59 /dev/i2c-6
crw------- 1 root root 89,  7 Aug 10 12:59 /dev/i2c-7
crw------- 1 root root 89,  8 Aug 10 12:59 /dev/i2c-8
crw------- 1 root root 89,  9 Aug 10 12:59 /dev/i2c-9

我需要运行sudo chmod 777 /dev/i2c-*并将权限更改为:

crwxrwxrwx 1 root root 89,  0 Aug 10 12:59 /dev/i2c-0
crwxrwxrwx 1 root root 89,  1 Aug 10 12:59 /dev/i2c-1
crwxrwxrwx 1 root root 89, 10 Aug 10 12:59 /dev/i2c-10
crwxrwxrwx 1 root root 89, 11 Aug 10 12:59 /dev/i2c-11
crwxrwxrwx 1 root root 89,  2 Aug 10 12:59 /dev/i2c-2
crwxrwxrwx 1 root root 89,  3 Aug 10 12:59 /dev/i2c-3
crwxrwxrwx 1 root root 89,  4 Aug 10 12:59 /dev/i2c-4
crwxrwxrwx 1 root root 89,  5 Aug 10 12:59 /dev/i2c-5
crwxrwxrwx 1 root root 89,  6 Aug 10 12:59 /dev/i2c-6
crwxrwxrwx 1 root root 89,  7 Aug 10 12:59 /dev/i2c-7
crwxrwxrwx 1 root root 89,  8 Aug 10 12:59 /dev/i2c-8
crwxrwxrwx 1 root root 89,  9 Aug 10 12:59 /dev/i2c-9

相关内容