3 ms·
I would love it if I could just use my Mac's Keychain Access from the command line
by asimpletune 3y ago
I would love it if I could just use my Mac's Keychain Access from the command line
- asimpletune 3y agoApparently `security` is exactly that
- bbkane 3y agoYes, but it's super awkward to actually use day to day I've got something of a wrapper script at https://github.com/bbkane/dotfiles/blob/8573e44d0f9fb5ddcbdcc1ef10a5345132c71fe1/bin_common/bin_common/envwarden.py https://github.com/bbkane/dotfiles/blob/8573e44d0f9fb5ddcbdc... Its getting a bit too unwieldy to stay as a single Python file and add tests and features, so I'm rewriting it in Go (nothing useful yet though)
- sxldier 3y agoI have a simple workflow I use for ENV vars. Another comment noted a script written which likely does more but I haven’t fully read the code. Here’s my simple workflow in case someone is interested. Create a DB in MacOS keychain called envs: security create-keychain -P envs Then use these shell functions: which get-env get-env () { security find-generic-password -s "$1" -w envs } which add-env add-env () { security add-generic-password -a "$USER" -s "$1" -w "$2" envs } Then add one via: add-env ENVNAME SECRET Example using it: ENVVAR=“$(get-env ENVNAME)” ./script.sh
- errata_piccata 3y agothis is gold, thank you
- sxldier 3y agoHappy it was helpful! Neglected to mention that your entry with the password will be stored in the shell history. You can prefix a space and have those commands (prefixed with a space) to be ignored in shell history. Alternative is to use `read` to pass the password in and hide the input. I can rewrite it for you if that’ll help.