1

I would like to execute something like rtcwake -m off -s 60 without entering a password.

I used visudo to write the following line into /etc/sudoers: %sudo ALL = NOPASSWD: /sbin/shutdown, /sbin/poweroff, /sbin/halt, /sbin/reboot

Now I can shutdown without entering a password. However, using rtcwake without password does not work. Instead, I get the following message:

rtcwake: assuming RTC uses UTC ... rtcwake: wakeup from "off" using /dev/rtc0 at Fri Dec 18 17:45:43 2015 shutdown: Need to be root

What is missing?

0

Since you're already trusting the user to shut down the system at any time, let them call rtcwake as root. Run visudo and add /usr/sbin/rtcwake to the line with /sbin/shutdown and so on.

  • Without sudo chmod ugo+r rtc0 I still get the error message: rtcwake: open failed: /dev/rtc0: Permission denied. – MrX Dec 21 '15 at 13:09
0

You can create a new udev rule to achieve that.

Create a new 40-rtc-permissions.rules file in /lib/udev/rules.d or /etc/udev/rules.d (depending on your distro) where you can put the following line

KERNEL=="rtc0", GROUP="wheel"

Group doesn't have to be wheel. It can be whichever user group you want to have access to the rtc0 device.

-1

Got it. I added the following line to /etc/rc.local:

sudo chmod ugo+r rtc0

and with %sudo ALL = NOPASSWD: /sbin/shutdown, /sbin/poweroff, /usr/sbin/rtcwake in /etc/sudoers. Note that I do not care about security because my application is running on a dedicated computer which does not run critical tasks.

edit: included /usr/sbin/rtcwake in /etc/sudoers according to Gilles answer.

  • Apart from embedded systems without udev, chmod … /dev/rtc0 won't survive a reboot. chmod +s /sbin/shutdown allows anyone to run shutdown, so it's a security hole unless you're the sole user of the machine and it doesn't run any software that risks having a security hole. – Gilles Dec 19 '15 at 22:06

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.