For example, I want to allow sudo shutdown -c
to always be run without entering a password, but sudo shutdown
without -c
to always require a password (even if I've authenticated to sudo
previously).
1 Answer
To change your sudo configuration you need to edit you /etc/sudoers file by using visudo (Only use this because it has validation included. If you don't know how to use vi here are the quick basics you need to edit the file). To allow certain parameters there is an answer here. So you would basically add something like
user ALL=(root) NOPASSWD: /usr/bin/shutdown -c
to the file to allow all users to excecute shutdown -c
without entering a password. To make sudo allways ask for a password you can set the timeout to 0 by adding
Defaults timestamp_timeout = 0
this is not command specific (sorry couldn't find anything better) but will ask for a password for all commands that need one to execute (ie there is no NOPASSWD
option specified).
For more details on what you can do with your sudoers file see the official page.