[英]Connect ssh server through nodejs code with ssh key and server name
我具有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
您是否嘗試用“密碼”替換“ privateKey”並輸入密碼。 它可能不是最安全的,但通常可以正常工作。 除非您必須使用id-rsa的私鑰
ssh = new node_ssh()
ssh.connect({
host: 'qa-trinath01.my-qa',
username: 'tanantham',
port: 27017,
password: 'YourPasswordHere'
}).then(function() {
console.error('Success: ');
}).catch((error) => {
console.error('ERROR: ', error);
});;
app.listen(3001);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.