代码之家  ›  专栏  ›  技术社区  ›  Saddy

Node.js子进程未能通过GitHub ssh身份验证

  •  0
  • Saddy  · 技术社区  · 7 年前

    您好,我正在创建Node.js应用程序,以便在自动推送时更新代码。

    问题

    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}`);
    

    命令运行:

    cd /mp/ && git pull origin deployment
    

    脱离子进程vrs。子进程中

    enter image description here

    编辑:

    从密钥中完全删除密码短语似乎可以解决这个问题,但出于安全原因,我更愿意将它放在密钥中。

    1 回复  |  直到 7 年前
        1
  •  1
  •   kbsbng    7 年前

    如果您正在为ssh密钥使用ssh代理,请尝试转发 SSH_AUTH_SOCK SSH_AGENT_PID 子进程的环境变量,如下所示:

    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) => {
                // ...
            });