I need to run some git commands from a ruby on rails application. I have the ssh private key stored in an env var. How can I run git commands using the ssh keys from the env var without dumping it on the filesystem?
CodePudding user response:
After some digging I found a solution using openssl:
echo "#{private_key}" | openssl rsa -passin pass:$PRIVATE_KEY_PASSPHRASE | ssh-add -
CodePudding user response:
Assuming your key does not have passphrase, you can try adding it to an ssh-agent (that you can start automatically):
ssh-add - <<< "${SSH_PRIVATE_KEY}"
With passphrase, you would need to enter it somehow, which is not practical in your case.
The alternative is indeed to dump it to a file, but it can be a temp file which will be cleaned up.
In that case, set GIT_SSH_COMMAND
to 'ssh -i /tmp/TempFileGenerated
', and you git commands (clone/push/pull/...) will use that for any SSH URL.