Search code examples
linuxfile-permissionsudevscreen-brightness

How to change specific file permissions using udev rule?


I'm trying to let my user bob the permissions to change the screen brightness, which means: let bob read, write permissions for /sys/class/backlight/intel_backlight/brightness

using:

udevadm info -a -p /sys/class/backlight/intel_backlight/

shows that following result:

  looking at device '/devices/pci0000:00/0000:00:02.0/drm/card1/card1-eDP-1/intel_backlight':
KERNEL=="intel_backlight"
SUBSYSTEM=="backlight"
DRIVER==""
ATTR{actual_brightness}=="7500"
ATTR{bl_power}=="0"
ATTR{brightness}=="7500"
ATTR{max_brightness}=="7500"
ATTR{type}=="raw"

.
.
.

So I wrote a udev rule for that in /etc/udev/rules.d/30-brightness.rules

30-brightness.rules

KERNEL=="intel_backlight", SUBSYSTEM=="backlight", RUN+="/usr/bin/find /sys/class/backlight/intel_backlight/ -type f -name brightness -exec chown bob:bob {} \; -exec chmod 666 {} \;"

But event after a reboot the file permissions stays -rw-r--r-- 1 root root

So my question is how to change specific file permissions using udev rule and what am I doing wrong?


Solution

  • I have solved the problem,

    the dev-rule should look like this (without the backslashes)

    KERNEL=="intel_backlight", SUBSYSTEM=="backlight", RUN+="/usr/bin/find /sys/class/backlight/intel_backlight/ -type f -name brightness -exec chown bob:bob {} ; -exec chmod 666 {} ;"
    

    But note that the above RUN command won't work on the terminal command line (for that you need to have the backslashes)