Store a password into the mac keychain:
The following command stores a password into the keychainsecurity 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