Skip to content

Instantly share code, notes, and snippets.

@bepcyc
Created February 19, 2021 12:42
Show Gist options
  • Save bepcyc/d82aa267b3ba37984af69de8eab40967 to your computer and use it in GitHub Desktop.
Save bepcyc/d82aa267b3ba37984af69de8eab40967 to your computer and use it in GitHub Desktop.
How to add secret content (e.g. a private key) to a bitwarden and how to restore it back. Chezmoi template included.
SECRET_NAME=id_rsa
SECRET_PATH=~/.ssh/id_rsa
# store the secret content as an item in bitwarden
echo "{\"organizationId\":null,\"folderId\":null,\"type\":2,\"name\":\"${SECRET_NAME}\",\"notes\":\"$(base64 -w 0 ${SECRET_PATH})\",\"favorite\":false,\"fields\":[],\"login\":null,\"secureNote\":{\"type\":0},\"card\":null,\"identity\":null}" | bw encode | bw create item
bw sync # optional
# retrieve the secret
# assuming a single search result
bw list items --search id_rsa | jq -r '.[0].notes' | base64 -d > ${SECRET_PATH}
# in case you're using chezmoi here's a template that will retrieve that secret automatically
#$cat $(chezmoi source-path ${SECRET_PATH})
#{{ (bitwarden "item" "id_rsa").notes | b64dec }}
chezmoi execute-template "`cat $(chezmoi source-path ${SECRET_PATH})`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment