Skip to content

Instantly share code, notes, and snippets.

@bcopeland
Forked from davidblewett/lp-ssh-add.sh
Last active April 15, 2016 12:05
Show Gist options
  • Save bcopeland/3cabf6ff3fe94fcbd566 to your computer and use it in GitHub Desktop.
Save bcopeland/3cabf6ff3fe94fcbd566 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Import all SSH keys from LP
#
PREFIX=~
SSH_ASKPASS=$PREFIX/bin/lp-askpass.sh
export SSH_ASKPASS
# This is needed to force ssh-add to honor our SSH_ASKPASS.
DISPLAY=foo
export DISPLAY
CONTAINER="Secure Notes\SSH"
# For some reason, lpass ls includes the folder's ID
CONTAINER_ID=4532168026
for key_id in `lpass ls "${CONTAINER}" | grep -v $CONTAINER_ID | awk '{print substr($4, 0, length($4))}'`; do
KEY_ID=$key_id
export KEY_ID
# setsid is needed to force ssh-add to honor our SSH_ASKPASS.
$PREFIX/lpass show --field "Private Key" $key_id | setsid ssh-add /dev/stdin
done
#!/bin/sh
PREFIX=~/bin
if [ -z "$KEY_ID" ]; then
exit 1
fi
$PREFIX/lpass show --field Passphrase $KEY_ID
@davidblewett
Copy link

So I can't use the Private Key / Public Key fields because of https://forums.lastpass.com/viewtopic.php?f=7&t=94925 . The problem is that if you use the web UI, you can paste the full key in but it converts all carriage returns to spaces (thus corrupting the ASCII-armor). If I use lpass edit to edit the field, it only saves the first line. These 2 fields need to be made multi-line to be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment