我已为节点安装了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包来做到这一点。 知道我该怎么办吗?