Skip to content

Instantly share code, notes, and snippets.

@miquelbrazil
Last active June 11, 2020 15:23
Show Gist options
  • Save miquelbrazil/f8cd6939a3bc167333b1d12090f703f2 to your computer and use it in GitHub Desktop.
Save miquelbrazil/f8cd6939a3bc167333b1d12090f703f2 to your computer and use it in GitHub Desktop.
Setup persistent SSH key in GitHub Action using a passphrase protected private key and without writing decrypted key to disk
# SSH Setup for GitHub Actions `run` keyword
# Previous Approaches
# Most pre-built GitHub Actions for CD with SSH keys don't allow for encrypted SSH keys.
# Current Approach
mkdir -p ~/.ssh
ssh-keyscan -H $HOST >> ~/.ssh/known_hosts
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
openssl rsa -in - <<< "${{ secrets.SSH_PRIVATE_KEY }}" -passin pass:${{ secrets.SSH_PASSPHRASE }} | ssh-add -
# References
# https://github.com/ngocquyhoang/deploy/blob/master/entrypoint.sh
# https://github.com/appleboy/ssh-action/blob/master/README.md
# http://blog.joncairns.com/2013/12/understanding-ssh-agent-and-ssh-add/
# https://www.ssh.com/ssh/agent
# http://rabexc.org/posts/pitfalls-of-ssh-agents
# https://github.com/shimataro/ssh-key-action/blob/develop/README.md
# https://www.redhat.com/archives/rhl-list/2008-January/msg04255.html
# https://github.com/deployphp/deployer/issues/1713
# https://misfra.me/2019/10/using-ansible-with-github-actions/
# https://ifireball.wordpress.com/2015/01/12/automatic-loading-of-ssh-keys-from-scripts/
# https://www.systutorials.com/how-to-decrypt-a-password-protected-rsa-private-key/
# https://www.techjunktrunk.com/bash/2017/11/10/ssh-add-from-environment-variable/
# https://github.com/hashicorp/vault/issues/2012
# https://stackoverflow.com/questions/7114990/pseudo-terminal-will-not-be-allocated-because-stdin-is-not-a-terminal
# https://www.exratione.com/2014/08/bash-script-ssh-automation-without-a-password-prompt/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment