20 lines
788 B
Bash
20 lines
788 B
Bash
|
#!/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
|