I am attempting to write a generic command-runner in Node.JS – however that’s not massively important.
My setup is as follows:
- I have a list of string commands that are executed using
child_process.exec
one after the other. - I want to run git from one of these commands, specifically a
pull
. - The location I am pulling from requires SSH authentication. HTTPS is not an option.
- My private key is passphrased.
- I am currently using
keychain
to managessh-agent
.
When running git pull
from the command line, it succeeds. When running my application as the logged-in user, it succeeds. However, when running my application using forever
, it fails.
The error I receive is Permission denied (publickey).
. I have tried calling keychain
as part of my command, but I cannot get it to recognise the credentials.
How can I fix this?
Advertisement
Answer
My mistake was taking the contents of .bash_profile
and using that to set up keychain
from my exec
.
What I needed to do was:
. $HOME/.keychain/$HOSTNAME-sh; git pull
I found this out by looking up examples of how to use keychain
with bash
scripts.