Monday, January 4, 2016

OSX: Command Line access to the KeyChain

Apple's Keychain has a command line utility called security(1), which allows access to information like accounts and passwords.  This is the command I use to return the password on it's on line on STDOUT.


security find-generic-password -s cli -gw | \
sed 's/^password...\(.*\).$/\1/g'
This has worked well for me in other utilities like mutt, mbsync and msmtp so that I don't have to hard code passwords in configuration files.

§