OS X Command Line – Export/Import Single Keychain Item

command linekeychainmacmacosSecurity

OS X has a command line tool called security that is made for working with keychains. The man page has examples of how to export all items of a specific type / all items for a specific keychain – but I don't understand how to export / import a single item.

What I would really like to do is update the password on a single IPSec XAuth Password item but I think maybe exporting, possibly deleting, then importing would be the closest thing to what I want.

I haven't had any luck finding examples or related questions for this task, and I've not used the security tool other than to list available keychains.

Best Answer

You can use find-generic-password or find-internet-password:

security find-generic-password -l 'keychain item name'
security find-internet-password -s accounts.google.com

-l mathes a label and -s matches a server string. Add -w to only print the password.

Related Question