Jump to content

Allow non-root user to access /sys/class/backlight/

Go to solution Solved by Nayr438,
10 minutes ago, TheLewisS1 said:

echo 0 | sudo tee /sys/class/backlight/rpi_backlight/bl_power

 

  • echo 'SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rules
  • sudo udevadm control --reload-rules && udevadm trigger

2020-09-04: Just a quick note, to avoid all of this you can just use " vcgencmd display_power 1 " instead. 

 

Hi there, I'm trying to get my Raspberry Pi Official Display to turn off when the screensaver kicks in.

I have everything working, except that the non-root uses is not allowed to modify the backlight (/sys/class/backlight/rpi_backlight/bl_power).

I did try making a udev rule and a group, but to no success because i was just blindly changing words.

I also tried chmod, but that got reverted quite soon after i had run the command.

 

Can anyone show me what to do?

 

Thanks!

UTC/GMT (Except during BST)

Link to comment
Share on other sites

Link to post
Share on other sites

Andrzej's approach is the proper one. The improper one would be

sudo chmod 777 /sys/class/backlight/rpi_backlight/bl_power

5950X/3080Ti primary rig  |  1920X/1070Ti Unraid for dockers  |  200TB TrueNAS w/ 1:1 backup

Link to comment
Share on other sites

Link to post
Share on other sites

11 minutes ago, AndrzejL said:

Use sudoers file to specify a sudo command that a user can execute without a password.

 

Example https://www.cyberciti.biz/faq/linux-unix-running-sudo-command-without-a-password/

 

Btw. its important to set it up as a ONE command not ALL commands.

Btw 2. If you get it wrong you may lose sudo access so... don't get it wrong.

 

Cheers.

 

Andrzej

Hi @AndrzejL. Thanks for your reply. Visudo says what I put is wrong. any ideas why?

pi ALL = NOPASSWD: sudo tee /sys/class/backlight/rpi_backlight/bl_power

I think i copied the website correctly.

UTC/GMT (Except during BST)

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, OddOod said:

Andrzej's approach is the proper one. The improper one would be

sudo chmod 777 /sys/class/backlight/rpi_backlight/bl_power

I had a feeling it wasn't the proper way when I did it! Thanks for confirming

UTC/GMT (Except during BST)

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, AndrzejL said:

Try

 


pi ALL = NOPASSWD: sudo /bin/tee /sys/class/backlight/rpi_backlight/bl_power

or


pi ALL = NOPASSWD: sudo /usr/bin/tee /sys/class/backlight/rpi_backlight/bl_power

 

depending where the tee is located which you can confirm by running

 


which tee

ALSO try putting entire command


sudo /usr/bin/tee /sys/class/backlight/rpi_backlight/bl_power

 

in ' ' or " ".

 

Cheers.

 

Andrzej

which tee

tells me it's in /usr/bin, so i used that one.

 

even with either the ' or " surrounding the command (sudo --> power) visudo still says there is a syntax error.

I entered 

pi ALL = NOPASSWD: sudo /usr/bin/tee /sys/class/backlight/rpi_backlight/bl_power

Thank you

UTC/GMT (Except during BST)

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, AndrzejL said:

What command do you actually use when you're trying to adjust that setting?

 

Cheers?

 

Andrzej

echo 0 | sudo tee /sys/class/backlight/rpi_backlight/bl_power

Under sudo, the command works fine.

 

Thanks!

UTC/GMT (Except during BST)

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, TheLewisS1 said:

echo 0 | sudo tee /sys/class/backlight/rpi_backlight/bl_power

 

  • echo 'SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rules
  • sudo udevadm control --reload-rules && udevadm trigger
Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, Nayr438 said:
  • echo 'SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rules
  • sudo udevadm control --reload-rules && udevadm trigger

That worked! Thank you @Nayr438.

 

Thanks for your help too @AndrzejL.

 

I'd never have been able to bodge that together successfully!

UTC/GMT (Except during BST)

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, AndrzejL said:

Nice one. You are using Arch linux aren't you?

Yes, for our all of our systems including servers.

Link to comment
Share on other sites

Link to post
Share on other sites

Hi @Nayr438 / @AndrzejL

 

Update, it actually doesn't work. 

It worked before I rebooted, but now I have rebooted and now it doesn't work and asks me for the password. I think this is because Raspian is set to keep sudo permissions for a set time after first sudo command...

Any ideas why? The line the command added is still there.

Edited by TheLewisS1

UTC/GMT (Except during BST)

Link to comment
Share on other sites

Link to post
Share on other sites

11 minutes ago, TheLewisS1 said:

Hi @Nayr438

 

Update, it actually doesn't work. 

It worked before I rebooted, but now I have rebooted and now it doesn't work and asks me for the password.

Any ideas why? The line the command added is still there.

does running "sudo udevadm control --reload-rules && udevadm trigger" again make it work as expected?

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Nayr438 said:

does running "sudo udevadm control --reload-rules && udevadm trigger" again make it work as expected?

Fresh reboot after clearing the rules file and running the two commands again.

Asks for password. 

After running your quoted command it works, but i fear that's because i've been given temporary root permissions. going to google to see how to turn it off for a bit.

 

UTC/GMT (Except during BST)

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, TheLewisS1 said:

Fresh reboot after clearing the rules file and running the two commands again.

Asks for password. 

After running your quoted command it works, but i fear that's because i've been given temporary root permissions. going to google to see how to turn it off for a bit.

 

are you running the command with sudo? it will ask for a password as long as you are telling it to run as root

 

  • echo 0 > /sys/class/backlight/rpi_backlight/bl_power
Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Nayr438 said:

are you running the command with sudo? it will ask for a password as long as you are telling to run as root

 

  • echo 0 > /sys/class/backlight/rpi_backlight/bl_power

oh for petes sake...

 

I was running as root. Duh.

Your original rule solution worked!

I'm sorry for my brain-fart!

 

Thanks again for real @Nayr438 / @AndrzejL

UTC/GMT (Except during BST)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×