1

I'm trying to write to /sys/class/backlight/intel_backlight/brightness and read from /sys/class/backlight/intel_backlight/max_brightness from a script I wrote. The problem is it requires root, and even if I chown or chmod it, the permissions reset after reboot.

I saw a solution to add something like:

user ALL = NOPASSWD: /sys/class/backlight/intel_backlight/brightness

using visudo but it doesn't work. What other options do I have?

phk
  • 5,953
  • 7
  • 42
  • 71
Zhinkk
  • 113
  • The file ownership and/or permissions of your script that you set by chown and chmod change on reboot? Where in your file system is the script located? – airhuff Jan 16 '17 at 02:21

1 Answers1

4

Files in /sys are not physical files on disk. They are virtual files that let you access information in your active kernel. The practical impact of that is that running chown, chmod, etc. on them is an ephemeral operation, as you have discovered. The entire filesystem view in /sys is generated by the kernel when the system boots, so there's no way to make persistent changes.

The easiest solution is to run your script as root. Using sudo is a common solution. You would need to give your user the ability to run your script as root. So, for example, if your script is installed as /usr/local/bin/configure-brightness, you could create /etc/sudoers.d/brightness with the following content:

yourusername ALL=(ALL) NOPASSWD:/usr/local/bin/configure-brightness

This file (/etc/sudoers.d/brightness) must be owned by root and have mode 440.

With this configuration in place, you can run:

sudo /usr/local/bin/configure-brightness

...and the script will run as root, which means it will be able to read from/write to files in /sys.

larsks
  • 34,737