Skip to content

Instantly share code, notes, and snippets.

@bkemper
Last active September 15, 2015 18:34
Show Gist options
  • Save bkemper/f3feea7dcbf4b513071e to your computer and use it in GitHub Desktop.
Save bkemper/f3feea7dcbf4b513071e to your computer and use it in GitHub Desktop.
Key management with OS X Keychain
# Too often developers leave keys in unencrypted files (e.g. bash_profile).
# The following are instructions to show how easy it is to create a new keychain
# for your project and fetch the keys.
# Create a keychain for your project
$ security create-keychain <your-project-name>.keychain
# Add keychain to search list (optional)
#
# @note The -s argument sets the list. If you have other keychains, you must
# include them.
# @see http://stackoverflow.com/a/22234506
# @todo Find a way to append a new keychain to the list
$ security list-keychains -d <your-username> -s login.keychain <your-project-name>.keychain
# Save your secret
#
# @note This command should be run in a shell without history.
# @see http://stackoverflow.com/a/8473732
$ security add-generic-password -a <your-username> \
-s <your-secret-name> \
-w "password with spaces" \
<your-project-name>.keychain
# Fetch your secret
$ security find-generic-password -s <your-secret-name> -w <your-project-name>.keychain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment