Tuesday, June 30, 2015

Store and Retrieve passwords in a Script using Mac KeyChains

Store a password into the mac keychain:

The following command stores a password into the keychain

security add-generic-password -a <username> -s <appname, friendly name> -p <password> -A -U


Retrieve the password from the mac keychain:

And this outputs the password to the stdout:
security find-generic-password -s <appname, friendly name> -g -w