Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: All configured authentication methods failed levels: 'client-authentication'

Tags:

node.js

ssh

I am using node.js ssh2 module.I have installed ssh2 module by executing the command 'npm install ssh2'.However, when I use ssh2 to connect to a remote server, it always output the error: [Error: All configured authentication methods failed] levels: 'client-authentication'

This is my code

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);

However, I can not connect successfully.I am sure the username and password are correct and I can connect successfully by SecureCRT.

it always output the error: [Error: All configured authentication methods failed] levels: 'client-authentication'

like image 606
PurpleCraw Avatar asked Nov 21 '22 11:11

PurpleCraw


1 Answers

Probably, you have to handle keyboard-interactive authentication (which is not the same as password). Try something like this:

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
});
like image 177
Евгений Савичев Avatar answered Nov 22 '22 23:11

Евгений Савичев