【问题标题】:SSH conection using ssh2-connect and ssh2-exec with nodeJSSSH 连接使用 ssh2-connect an ssh2-exec with node JS
【发布时间】:2021-06-16 02:11:19
【问题描述】:

我需要帮助才能在带有 nodeJs 的机器上建立 ssh 连接,我需要在登录“sudo /usr/bin/rootsh -i -u root”后首先使用此命令,然后进入此路径“cd . ." + "cd u01/scripts/" + "cat output.txt" 只报错

connect = require("ssh2-connect");
exec = require("ssh2-exec");

connect(
  {
    host: "XX.XX.XXX.XX",
    username: "XXXXXXXX",
    password: "XXXXX",
  },
  function (err, ssh) {
    child = exec(
      {
        command:
          "ssh -qtt username@host -- sudo /usr/bin/rootsh -i -u root; cd ..; cd u01/scripts/; cat saida.txt",
        ssh: ssh,
      },
      function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
        console.log(err);
      }
    );
  }
);

【问题讨论】:

    标签: node.js ssh


    【解决方案1】:

    成功了

    var host = {
      server: {
        host: "XX.XX.XXX.XX",
        username: "XXXXXXXX",
        password: "XXXXX",
      },
      commands: [
        "sudo /usr/bin/rootsh -i -u root",
        "cd ..; cd u01/scripts/; cat saida.txt",
      ],
    };
    
    var SSH2Shell = require("ssh2shell"),
      SSH = new SSH2Shell(host),
      callback = function (sessionText) {
        console.log(sessionText);
      };
    
    SSH.connect(callback);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-02
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-29
      相关资源
      最近更新 更多