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
.