24

I am trying to change the brightness by overwriting the value on this file:

sudo echo 5 > /sys/class/backlight/acpi_video0/brightness
-bash: /sys/class/backlight/acpi_video0/brightness: Permission denied

It doesn't work even when using sudo. However if I switch to super-user with su, it works. Why is that?

1
  • This action is restricted to sudo users only. I found an answer in this comment: The reason that this is set at su permissions is that a virus could conceivably make your screen dim and go bright at incredible speed ultimately damaging your hardware display. In the 90's I encountered a virus that would adjust the screen refresh Hertz so rapidly that your monitor would fry.
    – Alexey Vol
    Apr 3, 2019 at 10:58

6 Answers 6

24

The error happens because sudo elevates permissions for the command (sudo echo 5) but not the redirection to write the file (> /sys/class/backlight/acpi_video0/brightness). The actual bash shell needs permission to write, which is why it fails with sudo but works as root.

You can work around this by running the tee command as root to write to the file:

echo 5 | sudo tee /sys/class/backlight/acpi_video0/brightness

Note that this will also echo "5" to your terminal. This is a normal side effect of the tee command.

3
  • Credit goes to @duskwuff for the clever tee solution
    – mguymon
    Sep 20, 2012 at 0:45
  • 5
    I can't take credit for coming up with that -- it's a bit of UNIX folklore I picked up from who-knows-where.
    – user89623
    Sep 20, 2012 at 2:15
  • 2
    not working for me with /sys/class/drm/card0/device/pp_sclk_od cannot change the value
    – alexela
    Sep 15, 2017 at 20:25
23

As written in the Arch wiki (link), by default, only root can change the brightness by this method. To allow users in the video group to change the brightness, a udev rule such as the following can be used (replace the <vendor> with your vendor id. E.g. acpi_video0, intel_backlight) :

% cat /etc/udev/rules.d/backlight.rules
ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="<vendor>", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="<vendor>", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"

Then you need to add your user to the video group.

usermod -aG video <user>

After that this should work:

echo 5 > /sys/class/backlight/<vendor>/brightness
5
  • 1
    This method works for me, after replacing acpi_video0 by intel_backlight.
    – Mehdi
    May 5, 2019 at 10:06
  • 1
    Thx for your feedback. I've updated the answer. May 5, 2019 at 11:27
  • I'm using debian 10, and the output of groups showed that my non-root account is already in video. Also, I had to reboot before this answer worked for me.
    – xdavidliu
    Apr 15, 2020 at 1:07
  • This is the better way to do that. It must the accepted answer Jul 9, 2020 at 15:19
  • Should be an accepted answer. Now I can run a custom script to adjust backlight with non-root user
    – Pham
    Dec 6, 2020 at 3:11
2

If you didn't want 5 to be echoed this also works:

sudo sh -c 'echo 5 > /sys/class/backlight/acpi_video0/brightness'
0

I've been struggling with this problem on my VAIO VPCEG for quite a time. After doing everything mentioned in every forum I found something interesting:

After changing the boot parameter acpi_osi=Linux acpi_backlight=vendor and trying to manually change /sys/class/backlight/[vendor - in my case intel_backlight]/brightness, I realized that changing permission to this file from root to my user and restarting acpid service, this would allow me to use brightness keys flawlessly.

2
  • "changing permission to this file from root to my user" - this will get reset at next reboot.
    – TheEagle
    Jul 31, 2021 at 21:11
  • @TheEagle why? how to make it persistent? Dec 24, 2022 at 19:26
0

the below solutions works fine for me..

i am posting it as answer so that others might get help:

change the permission:

sudo chmod a+rw /sys/class/backlight/intel_backlight/brightness

now change brightness:

echo 400 > /sys/class/backlight/intel_backlight/brightness

in your case it would be: /sys/class/backlight/acpi_video0/brightness

6
  • 1
    Welcome to Super User! Please don't add "thanks" as answers. Invest some time in the site and you will gain sufficient privileges to upvote answers you like, which is the Super User way of saying thank you.
    – DavidPostill
    Jun 29, 2015 at 13:51
  • In addition you didn't really answer the question, which was "Why is that?"
    – DavidPostill
    Jun 29, 2015 at 13:52
  • thanks a lot.. for the information and really sorry.. just because of me.. you wasted your important time for guiding me..i will make sure this doesn't happen again Jun 29, 2015 at 15:49
  • It is not good practice to allow everyone to read and write a system config file like that.
    – lindhe
    Dec 18, 2015 at 15:15
  • I have some scenarios, where the screen starts functioning, yet the backlight value is still 0,
    – ransh
    Nov 26, 2016 at 21:22
0

The solution with tee is much better suited for scripting and such, but I found that simply editing the file with for example vim run using sudo works as well and is easier for me when I'm just doing it manually.

You must log in to answer this question.