From 5a705f4f914ba3c31e27cda7162a1b27a3bfa4e6 Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Mon, 26 Feb 2018 12:45:54 +0100 Subject: [PATCH] Add lastpass ssh key convenience script --- bin/lp-ssh-add | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 bin/lp-ssh-add diff --git a/bin/lp-ssh-add b/bin/lp-ssh-add new file mode 100755 index 0000000..484cd02 --- /dev/null +++ b/bin/lp-ssh-add @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +if [[ "$SSH_ASKPASS" == $0 ]]; then + exec lpass show --field Passphrase $_KEYID +fi + +if [[ -z "$1" ]]; then + lpass ls --color=never ssh | cut -d ' ' -f1 | fzf | xargs -n1 $0 + exit 0 +fi + +_tmp=$(mktemp -d) +cd $_tmp +mkdir -p $(dirname $1) +ln -s /dev/stdin $1 + +function cleanup { + rm -rf $_tmp +} +trap cleanup EXIT + +lpass show --field='Private Key' $1 | SSH_ASKPASS=$0 _KEYID=$1 ssh-add $1