3

I‘m trying to make a siri-shortcut which let you shutdown your mac.

https://www.icloud.com/shortcuts/7c625a68308740d9b84cc0eaa9353055

The command is:

sudo shutdown -h now

But when I run this command I must enter my password can I do something to run this command without the password?

Sorry for bad english

3

It could be configured to make sudo skip password prompt for specific command with /etc/sudoers.

# modify /etc/sudoers with visudo
# never open it directly with an editor
sudo visudo

Append the following conf into the file,

Cmnd_Alias SHUTDOWN_NOW = /sbin/shutdown -h now
%admin ALL=(root) NOPASSWD: SHUTDOWN_NOW

Done.

3

You can avoid the issue entirely by taking another approach to shutting down the computer:

osascript -e 'tell application "System Events" to shut down'

This will also prompt you to save any unsaved documents, just as if you'd selected "Shut Down" from the Apple menu.

  • Thanks!!! is this also working for sudo shutdown -h +10 or sudo killall shutdown? If yes, can you please exlpain me how? – JonathanXD12 Sep 13 at 17:55
  • No. The whole point is that this doesn't require sudo. – duskwuff Sep 13 at 17:56
  • I mean, is there another osascript command which let you cancel the shutdown or to shutdown the Mac in 10 minutes? Sorry for the misunderstanding :( – JonathanXD12 Sep 13 at 18:00
  • No. Again, this command works exactly as if you had initiated a shutdown from the menu bar. – duskwuff Sep 13 at 18:05
  • Okay thank you so much!!! :) – JonathanXD12 Sep 13 at 18:08
2

The common way to do this is to allow your user to run the shutdown command without entering a password.

You that by opening Terminal.app and then run the following command:

sudo visudo 

This gives you an editor where you can edit the sudoers configuration file.

Add the following line at the bottom:

jonathan ALL=(ALL) /sbin/shutdown 

After saving, you should be able to run shutdown with your user without having to enter a password.

Note that you should replace "jonathan" with your actual username.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .