欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

macos security find-generic-password 只查出一条记录吗 通义 chatgpt 有大用

security find-generic-password 命令在 macOS 上用于查找存储在钥匙串(Keychain)中的通用密码(Generic Passwords)。这个命令不会默认只查找一条记录,它会根据提供的参数(如服务名称、帐户名称等)来查找匹配的密码项。

如果你发现 find-generic-password 只返回了一条记录,那很可能是因为:

  1. 只有一个匹配的项:你的钥匙串中只有一个与该命令提供的参数匹配的通用密码项。

  2. 参数限制:你提供的参数(如 -s-a 等)非常具体,以至于只有一个项匹配。

  3. 权限问题:你可能没有足够的权限来查看所有的通用密码项。在 macOS 上,钥匙串访问权限是受限的,可能需要特定的权限或管理员身份才能访问某些密码项。

  4. 命令使用问题:你可能没有正确使用 find-generic-password 命令或其参数。确保你了解每个参数的含义,并提供了正确的值。

如果你想要查找所有的通用密码项(而不是仅根据特定参数查找),那么你可能需要使用其他方法,如 security dump-keychain 命令,并解析其输出来找到所有通用密码项。但请注意,dump-keychain 会输出钥匙串中的所有内容,包括证书、密钥和其他类型的密码项,因此你可能需要编写一些脚本来过滤出你感兴趣的通用密码项。

此外,请注意,从钥匙串中检索密码需要适当的权限,并且出于安全原因,密码本身可能不会在输出中直接显示。通常,你需要使用 -w 参数来请求密码的明文值(如果可用且你有权限)。


find-generic-password 仅显示第一个匹配项 


KeyChain Security command line tool works with find-internet-passwords but not find-generic-passwords
KeyChain 安全命令行工具适用于 find-internet-passwords,但不适用于 find-generic-passwords

Ask Question 问问题Asked 
12年7个月前问
Modified 3 years, 8 months ago
修改 3 年, 8 个月前
Viewed 20k times
浏览了 20k 次
9

Looking into using the command line tool for KeyChain. I am able to do a lot of the things through security; listing my multiple keychains, dumping them and setting defaults. Reading through tutorials and other postings I expect to find my passwords with
考虑使用 KeyChain 的命令行工具。我能够通过安全做很多事情;列出我的多个钥匙串,转储它们并设置默认值。通过阅读教程和其他帖子,我希望找到我的密码

security find-generic-password test

But I get
但是我明白了

security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security:SecKeychainSearchCopyNext:在钥匙串中找不到指定的项目。

This won't work in my default keychain or login.keychain. However, I am able to find my passwords listed as 'internet' with find-internet-password command. Can anyone explain why or what I am doing wrong? Sites I've been reading is the man page and http://blog.macromates.com/2006/keychain-access-from-shell/,
这在我的默认钥匙串或login.keychain中不起作用。但是,我能够使用 find-internet-password 命令找到我的密码列为“internet”。谁能解释一下我为什么或做错了什么?我一直在阅读的网站是手册页和 http://blog.macromates.com/2006/keychain-access-from-shell/

Improve this question
改进此问题
asked Nov 28, 2011 at 23:15
已问 十一月 28, 2011 在 23:15
Travis's user avatarTravis崔维斯3,1863 gold badges22 silver badges27 bronze badges

  • One minor issue I ran into with find-generic-password: if the service name (-s parameter) contains a period ('.') ('example.com', for example), I can run add-generic-password successfully but can't find the value with find-generic-password. – John McCarthy


    我在使用 find-generic-password 时遇到的一个小问题:如果服务名称(-s 参数)包含句点 ('.')(例如,'example.com'),我可以成功运行 add-generic-password,但找不到 find-generic-password 的值。–

     CommentedApr 19, 2022 at 22:17

Add a comment

2 Answers

15

Generic passwords are identified by their Service and Account attributes. For example, to search for a password for account "bar" of the "foo" service, use

security find-generic-password -a foo -s bar -g
解释

The -g option displays the value of the password at the end of the output.

The combination of service and account is guaranteed to uniquely identify a particular password. Other queries (comment, label, etc.) are possible, but they may match multiple passwords. find-generic-password displays only the first single matching item, which limits its usefulness for such queries.
服务和帐户的组合保证唯一标识特定密码。其他查询(注释、标签等)是可能的,但它们可能与多个密码匹配。仅显示第一个匹配项,这限制了其对此类查询的有用性。

Improve this answer
改进此答案
answered Nov 29, 2011 at 15:19
已回答 2011年11月29日 15:19
Karoy Lorentey's user avatarKaroy Lorentey卡罗伊·洛朗4,8732 gold badges29 silver badges28 bronze badges

  • What is the "Service" attribute? I don't see that label anywhere in the Keychain Access app on macOS Mojave 10.14.4. The metadata I see are "Name", "Kind", "Account", "Where", and "Comments". (I tried the obvious guess here, "Name", but that does not work.) – robenkleene罗本克林


    什么是“Service”属性?我在 macOS Mojave 10.14.4 上的“钥匙串访问”应用程序中的任何地方都看不到该标签。我看到的元数据是“名称”、“种类”、“帐户”、“位置”和“评论”。(我在这里尝试了明显的猜测,“名称”,但这不起作用。–

     CommentedApr 13, 2019 at 20:23 

  • 2Keychain Access uses the "Where" label for the Service attribute.
    Keychain Access 对 Service 属性使用“Where”标签。
     – Karoy Lorentey卡罗伊·洛朗


    Keychain Access 对 Service 属性使用“Where”标签。–

     CommentedApr 23, 2019 at 0:25

  • 1Isn't -s the service and -a the account? Seems they are inverted in the example. – Adrian Maire阿德里安·梅尔


    难道不是服务和帐户吗?似乎它们在示例中是颠倒的。–

     CommentedFeb 24, 2020 at 15:23

Add a comment
添加评论
3

A more accurate and up to date answer would be to use -w instead of -g if you only need password. I've seen people using -g and parsing output using awk/perl to get the password field, which is not needed (anymore). All you need to do is:
一个更准确和最新的答案是使用而不是只需要密码。我见过人们使用 awk/perl 使用和解析输出来获取密码字段,这(不再)需要了。
您需要做的就是:

security find-generic-password -a foo -s bar -w
解释

You may use
您可以使用
find-internet-password instead of find-generic-password command depending on where your password is stored in keychain.
您可以使用代替命令,具体取决于密码在钥匙串中的存储位置。

Improve this answer
改进此答案
answered Nov 5, 2020 at 15:37
已回答 2020年11月5日 下午3:37
Babak Farrokhi's user avatarBabak Farrokhi巴巴克·法罗基515 bronze badgesAdd a comment
添加评论

Your Answer 您的答案您的答案

来自 https://stackoverflow.com/questions/8303755/keychain-security-command-line-tool-works-with-find-internet-passwords-but-not-f



Mac OS X Keychain Access: "A default keychain could not be found" errorMac OS X 钥匙串访问:“找不到默认钥匙串”错误

Ask Question  问问题 Asked 12 年, 11 个月前 问Modified 2 years, 11 months ago修改 2 年, 11 个月前Viewed 52k times  浏览了 52k 次  Part of Mobile Development CollectiveMobile Development Collective的一部分14

I am trying to sign an iPhone app for publishing, so I am following the instructions to do so. Anyhow, when creating my Certificate Signing Request I get this error from Keychain Access: "A default keychain could not be found"我正在尝试对 iPhone 应用程序进行签名以进行发布,因此我正在按照说明进行操作。无论如何,在创建我的证书签名请求时,我从钥匙串访问中收到此错误:“找不到默认钥匙串”

I found no help on Google concerning this issue - can anybody help?我在谷歌上没有找到关于这个问题的帮助 - 有人可以帮忙吗?

Thanks! 谢谢! 

Improve this question 改进此问题 asked Jul 15, 2011 at 3:28已问 七月 15, 2011 在 3:28Pizzur22's user avatarPizzur22 披萨22 141 141 1 gold badge1 silver badge3 bronze badgesAdd a comment 添加评论 

4 Answers  4 个回答 

26

Sounds like you're missing your login.keychain. Either that, or you somehow un-set it as default. Look at your Keychains list in Keychain Access (View->Show Keychains). Do you have "login"? And is it bold? If either of those answers was "no", that's your problem. If you don't have a login keychain, go ahead and create one (File->New Keychain). If you don't have a bolded keychain, right-click your "login" keychain and there should be a menu item 'Make Keychain "login" Default'.听起来你错过了你的login.keychain。要么是这样,要么您以某种方式将其取消设置为默认值。在“钥匙串访问”(查看->显示钥匙串)中查看您的钥匙串列表。你有“登录”吗?它大胆吗?如果这些答案中的任何一个是“否”,那就是你的问题。如果您没有登录钥匙串,请继续创建一个(文件>新钥匙串)。如果您没有粗体钥匙串,请右键单击您的“登录”钥匙串,应该会有一个菜单项“将钥匙串”设为默认“。

Improve this answeranswered Jul 15, 2011 at 3:31Lily Ballard's user avatarLily Ballard185k34 gold badges386 silver badges348 bronze badges

Add a comment 添加评论 6

You can use security command in mac您可以在 mac 中使用安全命令

security list-keychains   # print all the keychains 
security default-keychain -s "<printed keychain using above command>"  
eg: security default-keychain "Users/myname/Library/Keychain/login-db"
解释

I had a problem with I create another keychain as the default keychain I wanted to delete that keychain and make the login keychain as default keychain. You can also use我在创建另一个钥匙串作为默认钥匙串时遇到了问题,我想删除该钥匙串并将登录钥匙串设置为默认钥匙串。您还可以使用

security delete-keychain "keychain name"  # to delete the keychain
解释

Improve this answeredited Jul 14, 2021 at 20:42Lee Irvine's user avatarLee Irvine3,2271 gold badge16 silver badges12 bronze badgesanswered May 14, 2021 at 15:58shubham rasal's user avatarshubham rasal1112 silver badges4 bronze badges

Add a comment 添加评论 4

Not allowed to create certificate:不允许创建证书:

Open Keychain and goto Keychain Access -> 'KeyChain First Aid'. Apply check on REPAIR radio button and enter Admin password in password field and click on START button. System will repair the keychain and then create certificate.打开钥匙串并转到钥匙串访问 ->“钥匙串急救”。应用检查“修复”单选按钮,然后在密码字段中输入管理员密码,然后单击“开始”按钮。系统将修复钥匙串,然后创建证书。

These steps worked for me.这些步骤对我有用。

Improve this answeranswered Sep 3, 2013 at 16:04Developer's user avatarDeveloper1071 silver badge5 bronze badges

  • There is no Keychain First Aid in Mac OS Sierra. What to do?Mac OS Sierra 中没有钥匙串急救。该怎么办?– KkMIW CommentedMar 10, 2017 at 5:22

  • On Catalina OS: You can blow away your default keychain and create a new one by clicking on Keychain Access>Preferences>[check Reset My Default Keychain]在Catalina OS上:你可以通过点击钥匙串访问>首选项>[检查重置我的默认钥匙串]来取消你的默认钥匙串并创建一个新的钥匙串– John Stack CommentedDec 20, 2019 at 15:14 

Add a comment 添加评论 2

You need to go into the Lib>Keychains and delete the contents in the folder.您需要进入 Lib>Keychains 并删除文件夹中的内容。

Delete References. Restart, and you should be a happy camper :)删除引用。重新开始,你应该是一个快乐的露营者:)

Improve this answeranswered Dec 2, 2014 at 18:35Greg Wiley's user avatarGreg Wiley211 bronze badgeAdd a comment 添加评论 

Not the answer you're looking for? Browse other questions tagged  or ask your own question.


来自  https://stackoverflow.com/questions/6702393/mac-os-x-keychain-access-a-default-keychain-could-not-be-found-error


普通分类: