我尝试了下面的代码,并使用了node-ssh-forward
NPM软件包。
const SSHConnection = require('node-ssh-forward').SSHConnection
var run = async () => {
const ssh = new SSHConnection({
username: 'Testuser',
endHost: 'example.com',
bastionHost: 'bastion01.aws.cloud',
privateKey: 'C:/Users/user/.ssh/id_rsa'
})
await ssh.executeCommand('uptime')
}
run()
错误消息:
[2020-09-10T22:10:31.046Z] (node:14284) UnhandledPromiseRejectionWarning: Error:
Timed out while waiting for handshake at Timeout._onTimeout (C:\Program Files\nodejs\node_modules\npm\bin\NodeJS\n
ode_modules\ssh2\lib\client.js:695:19)
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,
use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli
.html#cli_unhandled_rejections_mode). (rejection id: 3)