Skip to content

Instantly share code, notes, and snippets.

@ofstudio
Created December 14, 2014 16:39
Show Gist options
  • Save ofstudio/f136f473641109280333 to your computer and use it in GitHub Desktop.
Save ofstudio/f136f473641109280333 to your computer and use it in GitHub Desktop.
Get password from OS X Keychain shell / bash function
# Get password from OS X Keychain function
# Replace %ACCOUNT_NAME% with account name of Keychain item
# See `man security` for more info
get_pw () {
security 2>&1 >/dev/null find-generic-password -ga "%ACCOUNT_NAME%" \
| sed 's/password: "\(.*\)"/\1/'
}
# Don't store server credentials in plain text!
PASS=$(get_pw)
@mdavidn
Copy link

mdavidn commented Aug 23, 2018

Use -w rather than -g to eliminate the need for output redirection or sed. (Tested on High Sierra.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment