Skip to content

Instantly share code, notes, and snippets.

@rogeriopradoj
Forked from squeedee/1.Readme.MD
Created February 25, 2022 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogeriopradoj/67280c1dde913a90bde93361d6634ca2 to your computer and use it in GitHub Desktop.
Save rogeriopradoj/67280c1dde913a90bde93361d6634ca2 to your computer and use it in GitHub Desktop.
Adding your ssh key to lastpass

Setup

  1. Install lpass, the last pass command line tool
brew install lastpass-cli --with-pinentry
  1. Create a passphrase encrypted key and make sure you put the public key where you need it, eg: github

  2. Come up with a name for your lastpass shared note that is easy to search for.

  3. Create a lastpass shared note (use the web ui) from the template 2.lastpass-ssh-tool.sh included below.

  4. Replace {{USER-ID}} with your lastpass login email.

  5. Replace {{NOTE-NAME}} with the name of your lastpass shared note.

  6. Replace {{PRIVATE-KEY}} with your ssh private key:

KEY=$(cat <<-'EOF'
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,ETC....

3jEULKvVju0/SUEvv8CAbmGV5IskohMl3Nv3jEULKvVju0/SUEvv8CAbmGV5Isk1
........................
hu1rncm8AsfTvT2fr9ubHdo37JNSgPj4xGwkgnr9FCV7+AklMcHJMrSd8WoQwUMO
-----END RSA PRIVATE KEY-----
EOF
)
  1. Save your shared note

Usage

  1. Open your lastpass vault or chrome extension and search for your shared note
  2. Copy the first line of the shared note, without the #
  3. Paste into your terminal
  4. Respond with your lastpass password
  5. Respond with your ssh key passphrase.
# lpass login --trust {{USER-ID}} && bash -c "HOURS=8; `lpass show --notes 'Secure Notes/{{NOTE-NAME}}'`"
set -e
KEY=$(cat <<-'EOF'
{{PRIVATE-KEY}}
EOF
)
/usr/bin/ssh-add -D
rm -f /tmp/my-key
mkfifo /tmp/my-key
chmod 600 /tmp/my-key
set +e
echo "$KEY" > /tmp/my-key&
/usr/bin/ssh-add -t ${HOURS:-1}H /tmp/my-key
rm /tmp/my-key || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment