add ssh uploader

This commit is contained in:
Russ Long 2020-07-08 13:36:20 -04:00
parent ad480f6362
commit 18302eed49
2 changed files with 32 additions and 0 deletions

View File

@ -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 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` 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```

19
bw-ssh-uploader.sh Executable file
View File

@ -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