最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

节点simple

IT培训 admin 8浏览 0评论

节点simple

我正在尝试使用Node simple-ssh库连接到Ubuntu EC2机器。

代码:

const SSH = require('simple-ssh')
const fs = require('fs')

var ssh = new SSH({
    host: 'my-hostname',
    user: 'ubuntu',
    pass: fs.readFileSync("key.pem")
});

ssh.exec('echo $PATH', {
    out: function(stdout) {
        console.log(stdout)
    }
}).start()

当我运行node app.js时,它不会输出任何内容。也没有迹象表明它实际连接到机器上。它运行2-3秒,然后退出没有错误。

此外,我尝试输入随机密钥作为pass。这使得程序运行得更快,这表明错误的密钥会立即失败,而正确的密钥会在退出之前到达某个地方。但exec命令似乎没有运行。我试图mkdir和目录没有出现。

凭证100%正确,我可以通过Putty使用它来连接到机器。

回答如下:

Read the manual。

config.host {String}:主机名

config.port {Number}:端口号(默认值:22)

config.user {String}:用户名

config.pass {String}:密码

config.timeout {Number}:连接超时(以毫秒为单位)(默认值:10000)

config.key {String}:SSH密钥

config.passphrase {String}:密码短语

你应该使用key而不是pass

节点simple

我正在尝试使用Node simple-ssh库连接到Ubuntu EC2机器。

代码:

const SSH = require('simple-ssh')
const fs = require('fs')

var ssh = new SSH({
    host: 'my-hostname',
    user: 'ubuntu',
    pass: fs.readFileSync("key.pem")
});

ssh.exec('echo $PATH', {
    out: function(stdout) {
        console.log(stdout)
    }
}).start()

当我运行node app.js时,它不会输出任何内容。也没有迹象表明它实际连接到机器上。它运行2-3秒,然后退出没有错误。

此外,我尝试输入随机密钥作为pass。这使得程序运行得更快,这表明错误的密钥会立即失败,而正确的密钥会在退出之前到达某个地方。但exec命令似乎没有运行。我试图mkdir和目录没有出现。

凭证100%正确,我可以通过Putty使用它来连接到机器。

回答如下:

Read the manual。

config.host {String}:主机名

config.port {Number}:端口号(默认值:22)

config.user {String}:用户名

config.pass {String}:密码

config.timeout {Number}:连接超时(以毫秒为单位)(默认值:10000)

config.key {String}:SSH密钥

config.passphrase {String}:密码短语

你应该使用key而不是pass

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论