尝试使用量角器进行 SSH

Trying to SSH using protractor

我是 运行 我的 windows 虚拟机上的量角器,需要在 linux 虚拟机上执行一些命令。我正在尝试使用 SSH 来做同样的事情。我试过使用 'simple-ssh'、'remote-exec' 和 'ssh-exec.它们的问题都是一样的,量角器测试完成且没有任何错误,但未建立 SSH 连接。奇怪的是它也没有抛出任何错误,我试过输入错误的 IP,但仍然没有抛出任何错误。我已经在同一台机器上通过 python 尝试过 SSH,它运行完美。

这是我直接尝试使用的文档中的一段代码。

var ssh = new SSH({
             host: 'xx.xx.xxx.xx',
             user: 'xxxxx',
             pass: 'xxxxx'
         });

         ssh.exec('ls -lh', {
            out: function(stdout) {
                console.log(stdout);
            }
        }).start();

想通了。

我在茉莉花2中使用了ssh2 package to establish an interactive SSH session. Then I synchronized it with jasmine using done()

使用 Maciej Ciach 的 来解决同步问题。

这是一个完美运行的'It'块

it("trying ssh connection", function (done) {
        var conn = new Client();
        conn.on('ready', function () {
            console.log('Client :: ready');
            conn.shell(function (err, stream) {
                if (err) throw err;
                stream.on('close', function () {
                    console.log('Stream :: close');
                    conn.end();
                }).on('data', function (data) {
                    console.log('OUTPUT: ' + data);
                });
                stream.end('ls \nexit\n');
                done();
            });
        }).connect({
            host: 'xx.xx.xxx.xx',
            port: 22,
            username: 'x',
            privateKey: require('fs').readFileSync('file_path')

        });
    })

显然,您首先需要将 public ssh 密钥添加到服务器上的受信任密钥列表中。 你可以阅读它 here

如果您使用 windows,则在 Powershell 中执行这些命令。