Sudo permission denied but su grants permission

permissionssusudo

this is the first occurrence where su was required for me.

I read an article about changing the value in /sys/devices/virtual/backlight/acpi_video0/brightness to alter my laptop's screen brightness.

I first noticed that when I would $ sudo echo 10 > brightness I would get permission denied.

I switched to root using su and # echo 10 > brightness changed my brightness almost instantly.

The last weird thing to me happened when I tried # echo 20 > brightness (maxbrightness file holds the value 15) and I got a write error

Could someone explain this difference between sudo and su to me? Understanding the write error would be an added bonus. Any help, pointers, and/or links would be much appreciated.

Best Answer

Redirection does not work that way. Appending > to a command will run that redirection as the invoking user (you) and not as root. Do it with tee:

echo 20 | sudo tee /sys/devices/virtual/backlight/acpi_video0/brightness

or by invoking the command in a separate privileged shell:

sudo bash -c "echo 20 > /sys/devices/virtual/backlight/acpi_video0/brightness"
Related Question