diff --git a/README.md b/README.md index 325d242..53b902c 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,16 @@ Used to unlock a bitwarden vault and set the appropriate environment variables t 4. Run `bw-unlock` and imput your Bitwarden Master Password when prompted 5. Run any Bitwarden command to ensure the script worked, like `bw list items` + +## bw-ssh-uploader.sh + +Used to upload a directory of ssh keys to bitwarden, placing public key in the note field, and private key as an attachment. + +### Usage Instructions + +1. Copy the file to a location of your choosing, I use `/home/$USER/scripts` + +2. Mark it as executable + +3. Run script like this: +```/home/$USER/scripts/bw-ssh-uploader.sh /path/to/directory/of/keys $COLLECTIONID $ORGID``` diff --git a/bw-ssh-uploader.sh b/bw-ssh-uploader.sh new file mode 100755 index 0000000..6238261 --- /dev/null +++ b/bw-ssh-uploader.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# To upload a directory of SSH Keys to Bitwarden as notes, and move them to a specified collection +# Bitwarden vault must be unlocked prior to use + +SSHDIRECTORY=${1} +COLLECTIONID=${2} +ORGID=${3} + +for key in $(find $SSHDIRECTORY -type f | grep pem); do + #echo $key + keyname=$(echo $key | awk -F"/" '{print $NF}'| awk -F"." '{print $1}') + #echo $keyname + pubkey=$(ssh-keygen -y -f $key) + #echo $pubkey + item=$(echo '{"folderId":null,"type":2,"name":"'$keyname'","notes":"Public Key: '$pubkey'","favorite":false,"fields":[],"login":null,"secureNote":{"type":0},"card":null,"identity":null}' | bw encode | bw create item) + itemid=$(echo $item | jq -r .id) + bw create attachment --file $key --itemid $itemid + echo '["'$COLLECTIONID'"]' | bw encode | bw share $itemid $ORGID +done