Why is my Node SSH 2 authentication failing?

I want to establish a node ssh2 connection to an HPe Comware 5510. I can connect to other devices but not to this one. I know there are different types of authentication but they always fail.

this is my code:

const router =  require("express").Router();

var Client = require('ssh2').Client;

router.post("/", (req, res)=>{

    let json = req.body;
    var conn = new Client();
    conn.on('ready', function() {
        console.log('Client :: ready');
        let count = 0;
        let result = {};
        let cmd = null;
        let block = ""

        conn.shell((err, stream) => {
                if (err) res.json({err:err})
                stream.on('close', () => {
                    console.log('Stream :: close');
                }).on('data', (data) => {
                data = data.toString();

                    console.log('OUTPUT: ' + data);

                if(cmd) {
                    result[count + "- "+ cmd.value] += data;

                if(data.endsWith("# ")) {
                    cmd = json.cmds[count];
                    if (!cmd) return stream.end("exit\n");

                    if (cmd.type == "cmd") stream.write(cmd.value + "\n");
                    if (cmd.type == "block") stream.write(cmd.value + "\n");



    }).on('keyboard-interactive', function (name, descr, lang, prompts, finish) {
            var password = json.credentials.password;
            return finish([password]);
    }).on('error', function(err) {
        host: json.ip,
        port: 22,
        username: json.credentials.username,
        password: json.credentials.password,
        tryKeyboard: true

I believe that the problem is that it never executes the keyboard-interact code.

when I try to connect I get this error:

{ Error: All configured authentication methods failed
    at doNextAuth (/home/ccuartero/node/autocmd/node_modules/ssh2/lib/client.js:413:17)
    at tryNextAuth (/home/ccuartero/node/autocmd/node_modules/ssh2/lib/client.js:484:5)
    at SSH2Stream.onUSERAUTH_FAILURE (/home/ccuartero/node/autocmd/node_modules/ssh2/lib/client.js:597:5)
    at SSH2Stream.emit (events.js:198:13)
    at parsePacket (/home/ccuartero/node/autocmd/node_modules/ssh2-streams/lib/ssh.js:3682:10)
    at SSH2Stream._transform (/home/ccuartero/node/autocmd/node_modules/ssh2-streams/lib/ssh.js:701:13)
    at SSH2Stream.Transform._read (_stream_transform.js:190:10)
    at SSH2Stream._read (/home/ccuartero/node/autocmd/node_modules/ssh2-streams/lib/ssh.js:253:15)
    at SSH2Stream.Transform._write (_stream_transform.js:178:12)
    at doWrite (_stream_writable.js:415:12) level: 'client-authentication' }

Read more here: https://stackoverflow.com/questions/67380304/why-is-my-node-ssh-2-authentication-failing

Content Attribution

This content was originally published by StackThePile at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: