This is asked as a follow up as this SO:
Add a keychain to search list?
We know how to add a new create keychain to the search list by:
security list-keychains -s `security list-keychains | xargs` $NEW_KEYCHAIN
However, how do we remove it afterwords? After calling this multiple times (intentionally), we end up having this:
$ security list-keychains
"/Users/jenkins/Library/Keychains/login.keychain-db"
"/Users/jenkins/Library/Keychains/foo.keychain-db"
"/Users/jenkins/Library/Keychains/foo.keychain-db"
"/Library/Keychains/System.keychain"
Notice that we have multiple entries of foo.keychain-db there.
This may not be ideal, but we can simply call it again with the entries that we want to keep. For example, in this case:
$ security list-keychains -s /Users/jenkins/Library/Keychains/login.keychain-db /Library/Keychains/System.keychain
And it will be the result that we want:
$ security list-keychains
"/Users/jenkins/Library/Keychains/login.keychain-db"
"/Library/Keychains/System.keychain"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With