如何通过Node.js中的堡垒主机SSH到EC2实例

时间:2020-09-10 22:20:24

标签: node.js npm ssh bastion-host

我尝试了下面的代码,并使用了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)

0 个答案:

没有答案