12

I'm starting X as a user and need to set my keyboard brightness in /sys/class/leds/asus\:\:kbd_backlight/brightness. The /sys/ directory gets recreated after reboot, so the permissions will reset too. How do I set it up so I don't need to make the file writable by all users after every boot?

I'm using Archlinux with SDDM as the login manager and KDE as DE.

  • 2
    You could put a command in a systemd boot service. – goldilocks Mar 23 '13 at 13:52
  • Are you meaning to create a own systemd service which set the permissions? Or do you talk from a specific file? – xoned Mar 23 '13 at 14:04
  • The former. "Service" is the systemd term, even though in this case it would just be a one-off command and not a daemon. You could make it a kind of "miscellaneous stuff" service like rc.local is under sysV. In this case the service just runs a shell script, and you put the command in there. – goldilocks Mar 23 '13 at 14:31
13

No you can't, the permission of sysfs is defined in kernel space and can't be changed with userspace tools (unless with kernel side support).

But for your own problem, you could setup a sudo entry that allow everyone to write to that path, i.e ALL ALL = (ALL) NOPASSWD: /usr/bin/tee /sys/class/leds/asus\:\:kbd_backlight/brightness

And when you write to that directory, use a script like this, echo 1 | sudo /usr/bin/tee "/sys/class/leds/asus::kbd_backlight/brightness"

  • I tried that, but it asks always for the password. I also tried to add a NOPASSWD: behind the (ALL). – xoned Mar 29 '13 at 16:19
  • @Timo can you try again? See my updates – daisy Mar 29 '13 at 22:55
  • It works now. The problem was that my entry was overwritten by another one without NOPASSWD. And i accepted your answer because it was easier as the other answers. Thanks all. – xoned Mar 30 '13 at 18:24
  • I am using linux Mint Debian in sony vaio and trying to create a file in /sys/devices/platform/sony-laptop/kbd_backlight to control the keyboard Backlight. I have changed the path in your code which leads to this error: bash: syntax error near unexpected token ('` The command I typed is ALL ALL = (ALL) NOPASSWD: /usr/bin/tee /sys/devices/platform/sony-laptop/kbd_backlight Please help – Indra Jun 14 '14 at 14:00
  • I couldn't get this working on an Ubuntu machine until I added a comma between /usr/bin/tee and /sys/class.... After a brief look at the grammar in man sudoers I suspect the comma is necessary. – Jake Mitchell May 2 '15 at 0:23
4

The /sys directory in Linux is fake, it is a view into the kernel dressed up as files. So to change permissions in it permanently means hackig the kernel, and that would be ill-advised. As the comments say, perhaps a systemd unit setting this would be a solution (in general, set the change up as part of the boot process).

4

I had a similar problem, I needed to set the permissions before running the nodered service. Following the comment of goldilocks I created this systemd script:

$ cat /etc/systemd/system/setledspermissions.service

[Unit]
Description=Set leds writable to everybody
Before=nodered.service

[Service]
Type=oneshot
User=root
ExecStart=/bin/bash -c "/bin/chmod a+w /sys/class/leds/led0/*"

[Install]
WantedBy=multi-user.target

After writing the service file I enabled it with

$ sudo systemctl enable setledspermissions.service
$ sudo systemctl start setledspermissions.service
$ sudo systemctl status setledspermissions.service
  • Is this generally the way to go when needing to grant write access to specific /sys/ paths? My use case is setting the screen backlight brightness on my ĺaptop. – Richrd Aug 9 '18 at 19:44
  • I guess it is because the sys path is recreated each boot. But i'm not expert enough to be sure about that. – hariseldon78 Aug 11 '18 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.