使用nodejs的基于主机的ssh身份验证

时间:2014-11-26 10:46:08

标签: node.js ssh

我已为节点安装了ssh2软件包,但无法使基于主机的身份验证正常工作。

var Connection = require('./node_modules/bis-package/node_modules/ssh2');
var conn = new Connection();

conn.on('ready', function() {
    conn.exec('cmviewcl -v -f line', function(err, stream) {
        if (err) throw err;

        stream.on('exit', function(code, signal) {
            console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
        }).on('close', function() {
            console.log('Stream :: close');
            conn.end();
        }).on('data', function(data) {
            console.log('STDOUT: ' + data);
        }).stderr.on('data', function(data) {
            console.log('STDERR: ' + data);
        });
    });
}).connect({
    host: 'server',
    port: 22,
    username: 'root'
});

我收到以下错误

Error: Authentication failure. Available authentication methods: publickey,gssapi-with-mic,password,hostbased
    at Connection._tryNextAuth (/opt/bis/node/node_modules/bis-package/node_modules/ssh2/lib/Connection.js:1010:13)
    at onUSERAUTH_FAILURE (/opt/bis/node/node_modules/bis-package/node_modules/ssh2/lib/Connection.js:2449:8)
    at Parser.<anonymous> (/opt/bis/node/node_modules/bis-package/node_modules/ssh2/lib/Connection.js:141:5)
    at Parser.emit (events.js:98:17)
    at Parser.parsePacket (/opt/bis/node/node_modules/bis-package/node_modules/ssh2/lib/Parser.js:488:12)
    at Parser.execute (/opt/bis/node/node_modules/bis-package/node_modules/ssh2/lib/Parser.js:249:14)
    at Socket.<anonymous> (/opt/bis/node/node_modules/bis-package/node_modules/ssh2/lib/Connection.js:536:18)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:748:14)
    at Socket.emit (events.js:92:17)

我们使用基于主机的身份验证,允许我们无密码登录。在Perl中,我使用以下内容:

my( $SSH ) = "/usr/bin/ssh -t -o PreferredAuthentications=hostbased 2>/dev/null";
$run->run( map { qq{$SSH $_ "$CMD"} } @hosts );

我不确定如何使用nodejs ssh2包来做到这一点。 知道我该怎么办吗?

1 个答案:

答案 0 :(得分:1)

目前还不支持基于主机的身份验证。我计划在即将发布的下一个主要版本中添加对它的支持。相关问题是here