【发布时间】:2018-12-05 00:14:32
【问题描述】:
我有 vpn 访问权限,所以我可以通过终端中的命令 ssh 到服务器
ssh qa-trinath01.my-qa
它在终端上工作正常。
但是从 nodejs,它不起作用。我的代码是
var express = require("express");
var app = express();
var node_ssh = require('node-ssh')
var
ssh = new node_ssh()
ssh.connect({
host: 'qa-trinath01.my-qa',
username: 'tanantham',
port: 27017,
privateKey: '/Users/tanantham/.ssh/id_rsa'
}).then(function() {
console.error('Success: ');
}).catch((error) => {
console.error('ERROR: ', error);
});;
app.listen(3001);
我得到的输出是
ERROR: { Error: getaddrinfo ENOTFOUND qa-trinath01.my-qa qa-trinath01.my-qa:27017
at errnoException (dns.js:50:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'qa-trinath01.my-qa',
host: 'qa-trinath01.my-qa',
port: 27017,
level: 'client-socket' }
有人可以建议 nodejs 代码连接到 ssh,我只有 ssh 密钥和 ssh 服务器名称详细信息。
ssh key -> /Users/tanantham/.ssh/id_rsa
server name -> qa-trinath01.my-qa
【问题讨论】:
-
这个stackoverflow.com/a/28385129/3957754 怎么样?您也可以尝试使用另一种语言来验证它是 node.js 中的错误还是网络问题。
-
你可以试试 node-ssh。这是一个教程:grizzlybit.info/blog/how-to-ssh-using-nodejs
标签: javascript node.js npm ssh devops