Skip to content

Instantly share code, notes, and snippets.

@kopiro
Last active April 10, 2022 20:57
Show Gist options
  • Save kopiro/a0d30b3697ca39909f6d9acc135e6220 to your computer and use it in GitHub Desktop.
Save kopiro/a0d30b3697ca39909f6d9acc135e6220 to your computer and use it in GitHub Desktop.
Execute sudo commands asking password interactively via macOS security dialog only one time

sudoize.sh

Asks for admin privileges via macOS security dialog and writes in the /etc/sudoers file this string:

youruser ALL=(ALL) NOPASSWD:ALL

allowing you to execute next sudo commands without asking for password via terminal.

desudoize.sh

Remove previous line in the /etc/sudoers file, resetting file as it was before.

#!/bin/bash
osascript -e "do shell script \"sed -i '/dotfiles-start/,/dotfiles-end/d' /etc/sudoers\" with administrator privileges"
#!/bin/bash
export LOCAL_USER=$(whoami)
osascript -e "do shell script \"echo \\\"#dotfiles-start\n${LOCAL_USER} ALL=(ALL) NOPASSWD:ALL\n#dotfiles-end\\\" >> /etc/sudoers\" with administrator privileges"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment