从脚本运行时如何使rsync识别ssh publickey(nodejs)

alz*_*rke 5 rsync node.js

奇怪的问题在这里。

运行通过ssh引发的调用rsync的脚本

“权限被拒绝(公钥)。rsync:连接意外关闭(到目前为止已接收0字节)[接收器]”

奇怪的是:

  1. ssh user @ host有效,因此ssh密钥均已正确设置
  2. 将脚本生成的命令记录并粘贴到终端作品中
  3. 从脚本运行whoami显示正确的用户,并且环境通过process.env传递给生成实例
  4. 从脚本运行ssh user @ host不会引发错误并返回缓冲区,因此似乎可以正常工作
  5. 运行脚本(仅执行已测试的命令)将引发以上错误

    var spawn = require('child_process').spawn;
    spawn('rsync', [
        '-avc',
        '--delete',
        '"'+src+'"' , 
        '--link-dest="'+path.join(dest, folder_name)+'"',
        '"'+path.join(dest, 'latest/')+'"'
        ],{ 
            cwd: process.cwd(),
            env: process.env
    });
    
    Run Code Online (Sandbox Code Playgroud)

3on*_*3on 4

尝试指定密钥的路径

rsync -avz -e "ssh -i /home/thisuser/cron/thishost-rsync-key" remoteuser@remotehost:/remote/dir /this/dir/
Run Code Online (Sandbox Code Playgroud)

  • 这个例子有效,它可能有很多参数:https://gist.github.com/3388314 (2认同)