Skip to content

Instantly share code, notes, and snippets.

@Ozzah
Last active December 4, 2020 01:16
Show Gist options
  • Save Ozzah/ce8f720e949ce10cf14c304c4d1a97ec to your computer and use it in GitHub Desktop.
Save Ozzah/ce8f720e949ce10cf14c304c4d1a97ec to your computer and use it in GitHub Desktop.
Generate two SSH keys (one with and one without a passphrase) and upload to LastPass using LastPass-CLI
#!/bin/bash
read -s -p "SSH passhprase for '$1'? " passphrase
printf "\n"
read -s -p "Confirm passphrase: " passphrase2
printf "\n"
if [[ "$passphrase" != "$passphrase2" ]]
then
>&2 echo "Passphrases do not match"
exit 1
fi
ssh-keygen -t rsa -b 4096 -f $1_key -C $1_key -N "$passphrase"
ssh-keygen -t rsa -b 4096 -f $1_nokey -C $1_nokey -N ""
printf "Bit Strength: 4096\nFormat: RSA\nPassphrase: %s\nPrivate Key: %s\nPublic Key: %s" "$passphrase" "$(cat $1_key)" "$(cat $1_key.pub)" | lpass add --non-interactive --sync=now "SSH Keys/$1_key" --note-type=ssh-key
printf "Bit Strength: 4096\nFormat: RSA\nPassphrase: %s\nPrivate Key: %s\nPublic Key: %s" "$passphrase" "$(cat $1_nokey)" "$(cat $1_nokey.pub)" | lpass add --non-interactive --sync=now "SSH Keys/$1_nokey" --note-type=ssh-key
lpass sync
echo "Done!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment