Thursday, May 2, 2024
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 414  / 3 Years ago, thu, october 28, 2021, 7:10:40

I am looking to migrate a Snoozer application I originally wrote in windows on AutoIt, which when it comes down to it is a Shutdown Snoozer.



I list faling asleep to a movie or show, but I wake up if my pc runs through the night. So I built an application which notifies you that there is a pending shutdown and you have 10 minutes to snooze this otherwise the PC shuts down. The application allows you to repeat this prompt for X times and on a Y interval.



My question is, in Ubuntu will I need sudo rights to shutdown. If so, how can I prevent the application from continually asking the user to authenticate as sudo in order to shutdown the system properly??


More From » application-development

 Answers
4

Yes, the user need to have sudo rights, but you can use NOPASSWD to skip password authentication anyway.



To allow a user to run specific commands, in this case, the shutdown command, edit the /etc/sudoers file, for example:



user ALL=/usr/bin/apt-get,/sbin/shutdown


A more detailed version which suits your requirement better (user can shut down using sudo shutdown -h now and reboot with sudo reboot. Users wishing to power down a system can also use poweroff or halt without password):



user hostname =NOPASSWD: /sbin/shutdown -h now,/sbin/halt,/sbin/poweroff,/sbin/reboot


You can use the following command to show what the user can run will tell us what commands the user can run with sudo:



sudo -U user –l

[#34420] Thursday, October 28, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ditery

Total Points: 9
Total Questions: 116
Total Answers: 119

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
;