在 Apple Script 中运行管理 shell 脚本时如何覆盖要求进行身份验证? [英] How to overwrite the asking for authentication when running an admin shell script in Apple Script?

查看:17
本文介绍了在 Apple Script 中运行管理 shell 脚本时如何覆盖要求进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个简单的程序,每次登录时都会在 UI 后面运行.在我的 applescript 中,我正在运行一个需要管理员身份验证的 sudo 命令.有没有办法在每次运行时覆盖对身份验证的需求?我不想每次登录后运行此脚本时都必须键入我的用户名和密码.有什么帮助吗?(用非常简单的术语来说,因为我是新手.)非常感谢!

I'm wanting to make a simple program that runs each time on login behind the UI. In my applescript I'm running a sudo command that requires admin authentication. Is there a way to overwrite the need for authentication each time it runs? I don't want to have to type my username and password each time this script runs after login. any help? (and in very simple terms to as I'm a novice.) Much Thanks!

推荐答案

您可以将您的用户名和密码放在 applescript 命令中,这样它就不会要求提供这些凭据.但是请注意,这些项目以纯文本形式存储在 Applescript 中,因此其他人可能会看到它们.这不是真的安全,但由您决定是否安全.注意:您不再需要在命令中使用sudo".

You can put your username and password in the applescript command so that it doesn't ask for those credentials. However note that these items are stored as plain text inside the applescript and thus it's possible for others to see them. It's not really secure but it's up to you to decide if it's safe. NOTE: you don't need "sudo" in the command any longer.

do shell script "whatever" user name "username" password "password" with administrator privileges

有一些方法可以将您的密码存储在钥匙串中并从 Applescript 中检索它,从而使其安全.如果您想这样做,那么您可以按如下方式创建密码项.

There are methods where you can store your password in the Keychain and retrieve it from the applescript, thus making it secure. If you want to do that then you create the password item as follows.

打开钥匙串访问应用程序并在左栏中选择钥匙串.然后点击File>New Password Item...,给它起个名字,在account里填上你的账号短名,然后输入密码.在密码列表中突出显示它并获取有关它的信息.在 Attributes 按钮下输入它的种类作为通用键.之所以选择这个,是因为它们并不多,而且搜索速度要快得多.无论您给它起什么名字,都必须在下面的您的密码名称"中输入代码.

Open Keychain Access application and select the keychain in the left column. Then click File>New Password Item..., give it a name, put your account shortname in account, and enter the password. Highlight it in the password list and get information on it. Under the Attributes button enter its kind as generic key. This is chosen because there aren't many of them and the search is much faster. Whatever name you give to it must be put in the code below in "Your Password Name".

现在从applescript你可以像这样使用它......

Now from applescript you can use it like this...

set myPass to getPW()

do shell script "whatever" user name "username" password myPass with administrator privileges

on getPW()
    do shell script "security 2>&1 >/dev/null find-generic-password -gl \"Your Password Name\" | awk '{print $2}'"
    return (text 2 thru -2 of result)
end getPW

祝你好运!

这篇关于在 Apple Script 中运行管理 shell 脚本时如何覆盖要求进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆