Error:read ECONNRESET - I cannot successfully authenticate with the hp-ux server in node.js

1.4k views Asked by At

I have a problem with the connection into a hpux server that we host locally in our local network. I get the following error:

Hello world
Connected to Nemesis
true
rejected: Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read',
  level: 'client-socket'
}
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read',
  level: 'client-socket'
}

Here is my code:

console.log('Hello world');

const { NodeSSH } = require('node-ssh');

const ssh = new NodeSSH();

ssh.connect({
    host: "server",
    username: "admin account",
    password: "password"
}).then(console.log("Connected to Nemesis"))

console.log(ssh.isConnected());

ssh.exec('hh_client', ['--json'], { cwd: '/', stream: 'stdout', options: { pty: true } }).then(fulfilled => {
    console.log("fulfilled:", fulfilled)
}).catch(rejected => {
    console.log("rejected:", rejected)
})

I believe it is connecting to the server OK, tested by changing the IP, where I get a message to say that it cannot find the server. That said, the username and password does not seem to be being used, as I can type the user and password wrong, and I get the same error message.

the exec code is just lifted from the npm website for the module.

for a little more context, I am fairly new to hpux and linux in general, as most of this is inherited. I have seen a lot of information about using RSA and public/private keys, but there are already some on the server and I don't want to overwrite anything in the .ssh folder if I can help it.

In terms of connecting via other methods, I can use the username and password using ssh user@server and connect in fine, and do anything I want on the server with full permissions.

Any help appreciated.

Thank you, Craig

1

There are 1 answers

1
David Bohbot On

Seing the exact same problem.

It's seems from the logs on the target server that the library is still trying to use key auth, maybe because we are not using it correctly or because it's simply considered insecure by the developers, or maybe they just negleted that option since most people won't use it for security reasons.

Here is the relevant server log:

Jan 23 20:43:55 debian sshd[6152]: error: kex_exchange_identification: banner line contains invalid characters
Jan 23 20:43:55 debian sshd[6152]: banner exchange: Connection from <source_ip_edited_for_privacy> port 42544: invalid format

Here is the code:

const readline = require("readline");
const { NodeSSH } = require("node-ssh");

// function to get input from user
const getInput = () => {
  // required to take input from user
  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
  });

  // required to connect
  const ssh = new NodeSSH();

  rl.question("What is the host? ", (host) => {
    console.log(host);
    rl.question("What is the user? ", (user) => {
      console.log(user);
      rl.question("What is the password?", (password) => {
        console.log(password);
        rl.question("What is the command?", (command) => {
          console.log(command);
          // Connect
          ssh.connect({
            host: host,
            username: user,
            password: password,
            //privateKeyPath: '/home/steel/.ssh/id_rsa'
          });
          // Excute Command
          ssh
            .execCommand(`${command}`, { cwd: `/home/${user}` })
            .then((result) => {
              //   rl.write(result.stdout);
              console.log("STDOUT: " + result.stdout);
              console.log("STDERR: " + result.stderr);
            })
            .catch((err) => {
              console.log(err);
            })
            .finally(() => {
              ssh.dispose();
              rl.close();
            });
        });
      });
    });
  });
};

getInput();