Node.js的子进程失败GitHub的ssh认证
目标
您好,我创建一个Node.js的应用程序时,一推自动进行更新我的代码。
问题
一切正常的话,除了,实际的git拉。回购协议是私有的,需要使用SSH,但是当我在终端使用相同的命令它的工作原理。我已经keychaining就这么不问我的密码。任何想法,如何解决这一问题?
相关代码
const exec = require("child_process").exec;
exec('cd ' + repo + ' && git pull origin deployment', (egitpull,stdoutgitpull,stderrgitpull)=>{
if(egitpull) return console.error(`git pull exec error:${egitpull}`)
console.log(`git pull stdout: ${stdoutgitpull}`);
console.log(`git pull stderr: ${stderrgitpull}`);
Command run:
cd /mp/ && git pull origin deployment
Out of child process vrs. in child process
Edit:
从键删除密码完全似乎解决了问题,但我更喜欢有它在那里出于安全原因。
回答如下:如果您使用的是SSH代理为你的SSH密钥,尝试转发SSH_AUTH_SOCK
和SSH_AGENT_PID
ENV变量子进程,就像这样:
exec('cd ' + repo + ' && git pull origin deployment',
{
env: {
SSH_AUTH_SOCK: process.env.SSH_AUTH_SOCK,
SSH_AGENT_PID: process.env.SSH_AGENT_PID
}
},
(egitpull,stdoutgitpull,stderrgitpull) => {
// ...
});