The order of parameters in sudoers is like this:
- root ALL=(ALL:ALL) ALL - This applies to user root
- root ALL=(ALL:ALL) ALL - This rule applies to all user root logged in from all hosts
- root ALL=(ALL:ALL) ALL - User root can run commands as all users
- root ALL=(ALL:ALL) ALL - User root can run commands as all groups
- root ALL=(ALL:ALL) ALL - These rules apply to all commands
Your addition myname ALL = /usr/bin/pmset
to sudoers contains the first, second and fifth parameters and therefore means user myname
on any host can run sudo pmset
. If they were a member of the %admin
group (as the first user created on macOS is) they would have been able to do this anyway.
What is doesn't do is tell sudo is that you don't want to enter a password which is done with the NOPASSWD parameter. Therefore you want, as the last line in sudoers for myname
:
myname ALL = NOPASSWD : /usr/bin/pmset
This will let user myname
enter sudo pmset
without prompting for a password. If you wish you can then make an alias as described in the other answer and add it to your ~/.bashrc
or ~/.zshrc