我正在使用node.js ssh2模块。我已经通过执行命令'npm install ssh2'安装了ssh2模块。但是,当我使用ssh2连接到远程服务器时,它总是输出错误: [错误:所有已配置的身份验证方法都失败]级别:'client-authentication'
这是我的代码
var Client = require('ssh2').Client
var conn = new Client();
var option = {
host: '10.171.65.154',
port: 22,
username: 'root',
password: '123456'
};
conn.on('ready', function(){
console.log('Client :: ready');
conn.sftp(function(err, sftp){
if(err) throw err;
sftp.readdir('home', function(err, list){
if(err) throw err;
console.dir(list);
conn.end();
});
});
}).on('error', function(err){
console.log(err);
}).connect(option);
但是,我无法成功连接。我确信用户名和密码是正确的,我可以通过SecureCRT成功连接。
它总是输出错误: [错误:所有已配置的身份验证方法都失败]级别:'client-authentication'
答案 0 :(得分:0)
可能您必须处理键盘交互式身份验证(与密码不同)。尝试这样的事情:
connection.on('ready', function(){
console.log("Connected!");
}).on('error', function(err){
console.error(err);
}).on('keyboard-interactive', function (name, descr, lang, prompts, finish) {
// For illustration purposes only! It's not safe to do this!
// You can read it from process.stdin or whatever else...
var password = "your_password_here";
return finish([password]);
// And remember, server may trigger this event multiple times
// and for different purposes (not only auth)
}).connect({
host: "your.host.or.ip",
port: 22,
username: "your_login",
tryKeyboard: true
});