Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a keychain to search list?

Tags:

macos

keychain

I need to add a .keychain file to my keychains search list for some automated build tools. Currently I'm using security list-keychains command:

list-keychains [-h] [-d user|system|common|dynamic] [-s [keychain...]]
        Display or manipulate the keychain search list.

This command let's you set the entire keychain search list, but it does not provide a way to simply add another keychain. So adding a keychain becomes a 2 step process.

  1. Run list-keychains and parse the output
  2. Then do something like list-keychains -s ${existing_chains} ${new_keychain}

While this works, it seems overly complicated and introduces a race condition.

Also it seems like open my.keychain will add it to the search list, but I tend to avoid using commands like open in scripting or headless environments.

Is there a simpler or better way to add a keychain to the search list?

like image 471
amrox Avatar asked May 10 '12 17:05

amrox


People also ask

How do I add keychain to my Mac?

In the Keychain Access app on your Mac, select a keychain in any of the Keychains lists other than the System Roots keychain. Note: You can't add a password item to the System Roots keychain. Choose File > New Password Item. Tip: To add a new keychain item quickly, click the New Keychain Item button in the toolbar.

How do I find my keychain passwords on my Mac?

Keychain Access lets you view the keys, certificates, passwords, account information, notes, or other information stored in a keychain. In the Keychain Access app on your Mac, if you don't see a list of keychains, choose Window > Keychain Viewer or press Command-1. Select the keychain that you want to view.

Is keychain password same as Apple ID?

Your login keychain password is normally the same as your user password (the password you use to log in to the computer). At login, if your keychain password somehow differs from your user password, it doesn't automatically unlock, and you're asked to enter the keychain's password.


1 Answers

A one line version of @mles solution above:

security list-keychains -d user -s $(security list-keychains -d user | sed -e s/\"//g) <new keychain>

The issue with directly piping in the output of security list-keychains -d user is it surrounds the results with quotes. Solution uses sed to strip them out.

like image 186
James Leitch Avatar answered Sep 24 '22 18:09

James Leitch