Skip to content
Advertisement

Running git from node.js as a child process?

I am attempting to write a generic command-runner in Node.JS – however that’s not massively important.
My setup is as follows:

  1. I have a list of string commands that are executed using child_process.exec one after the other.
  2. I want to run git from one of these commands, specifically a pull.
  3. The location I am pulling from requires SSH authentication. HTTPS is not an option.
  4. My private key is passphrased.
  5. I am currently using keychain to manage ssh-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.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement