Skip to content

Instantly share code, notes, and snippets.

@johncarney
Last active September 4, 2025 15:06
Show Gist options
  • Select an option

  • Save johncarney/e3d7c53c77980cf92d4712f5bdc9a1c0 to your computer and use it in GitHub Desktop.

Select an option

Save johncarney/e3d7c53c77980cf92d4712f5bdc9a1c0 to your computer and use it in GitHub Desktop.
Simple macOS secrets management
# I sometimes need to securely manage credentials for external services for work
# purposes and these need to be available in environment variables. It would be
# nice to think that I only need these credentials for non-production
# environments, but that is not always the case. Rather than using .env files
# or similar plaintext mechanisms, I use macOS's `security` tool to add
# these credentials to my login keychain and store them in environment
# variables.
# Add a generic password to yur macOS login keychain. You will be prompted
# to enter the password.
security add-generic-password -a "$USER" -s my_sekr1t -w
# Export a generic password to an environment variable. You might want to
# put this in your .zshrc or .bashrc.
export MY_SEKR1T="$(security find-generic-password -a "$USER" -s my_sekr1t -w)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment