Skip to content

Instantly share code, notes, and snippets.

@georgjaehnig
Last active March 7, 2021 16:04
Show Gist options
  • Save georgjaehnig/217c004decb58877a2eebd05788d1dee to your computer and use it in GitHub Desktop.
Save georgjaehnig/217c004decb58877a2eebd05788d1dee to your computer and use it in GitHub Desktop.
Add an encrypted SSH key with `ssh-add` and get the password from `pass` (passwordstore.org)
#!/bin/bash
# Script adapted from
# https://stackoverflow.com/a/13034313
#
# Requirements:
# - "expect" https://linux.die.net/man/1/expect
SSH_KEY_FILE="FULL_PATH_TO_SSH_FILE" # example: "/Users/alice/.ssh/id_rsa"
PASS_NAME="NAME_OF_FILE_IN_~/.password-store" # example: "my-ssh-passphrase"
pass=$(pass show "${PASS_NAME}")
expect << EOF
spawn ssh-add "${SSH_KEY_FILE}"
expect "Enter passphrase"
send "$pass\r"
expect eof
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment