通过GUI获取sudo要求输入密码 [英] Getting sudo to ask for password via the GUI
问题描述
我有一个在Mac上运行的lua脚本,需要调用sudo.
I have a lua script, running on the Mac, that needs to call sudo.
我希望Mac OS会自动显示一个密码请求对话框,但是相反,该命令失败,返回了256.
I'd hoped that Mac OS would automatically bring up a password request dialog, but instead it the command fails by returning 256.
反正我能实现目标吗?
蒂姆
推荐答案
快速简便的方法:像这样运行它
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'
正确且可配置的方式:使用授权服务中的AuthorizationExecuteWithPrivileges
API(在Security.framework中).
Proper and configurable way: use AuthorizationExecuteWithPrivileges
API from Authorization Services (in Security.framework).
两者都将显示标准的Mac OS X GUI,要求管理员密码,然后以root用户身份执行命令,与sudo相同,只是不会设置SUDO_USER
环境变量.
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.
如果您已经提升为root用户时需要从用户帐户下执行单个命令,则可以在它们前面加上/usr/bin/sudo -u $USER
.
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
.
这篇关于通过GUI获取sudo要求输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!