I want to run the below command

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

i cannot do it it like below beecause bash is the process that actually directs output to the root-owned brightness file.

sudo echo 1000 > /sys/class/backlight/intel_backlight/brightness

so how would i run this command but i

  • do not want to be prompted for root password
  • do not want to login as root, execute command and exit
  • should use available sudo permissions available for current user to execute command

What you're asking is impossible. Your current process is not being run by root, and only the root user can issue setuid. As such, another process has to be launched as the root user first (by using a setuid executable, in this case, sudo).

Here is the closest thing to what you're asking, with the impossible removed:

echo 1000 | sudo tee /sys/class/backlight/intel_backlight/brightness

If you don't want this to prompt for a password, add a line in /etc/sudoers (by using visudo), like so (replace rag with your username):

Cmnd_Alias BACKLIGHT = /usr/bin/tee /sys/class/backlight/intel_backlight/brightness, ! /usr/bin/tee /sys/class/backlight/intel_backlight/brightness *

this works as well. I do not mind being prompted for my own password

sudo bash -c "echo 1000 > /sys/class/backlight/intel_backlight/brightness".

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.