Getting sudo to ask for password via the GUI

依然范特西╮ 提交于 2019-12-03 11:07:18

Quick and easy way: run it like this

/usr/bin/osascript -e 'do shell script "/path/to/myscript args 2>&1 etc" with administrator privileges'

Proper and configurable way: use AuthorizationExecuteWithPrivileges API from Authorization Services (in Security.framework).

Both will display standard Mac OS X GUI asking for administrator password and then execute the command as root, the same way as sudo does except that SUDO_USER environment variables will not be set.

If you need to execute individual commands from under user account when you're already elevated to root, you can prepend them with /usr/bin/sudo -u $USER.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!