nodejs-ssh2
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Node-SSH2 Extends Node-SSH

Installing

npm i nodejs-ssh2

or

yarn add nodejs-ssh2

Example

import { ClientSSH } from 'nodejs-ssh2';

const ssh = new ClientSSH();

await ssh.connect({
  host: 'localhost',
  username: 'ubuntu',
  password: '123'
});

await ssh.execCommand(`
    ls -la
    `, {
        onStderr: (chunk) => console.log(chunk.toString('utf8')),
        onStdout: (chunk) => console.log(chunk.toString('utf8'))
    });

await ssh.dispose();

Keyboard-interactive user authentication

In some cases you have to enable keyboard-interactive user authentication. Otherwise you will get an All configured authentication methods failed error.

Ubuntu server 22.04 LTS

Open file

sudo nano /etc/ssh/sshd_config

Add the line below

PubkeyAcceptedKeyTypes=+ssh-rsa

Restart the service sshd

sudo systemctl restart sshd.service

Example:

import { ClientSSH } from 'nodejs-ssh2';

const ssh = new ClientSSH();

await ssh.connect({
        host: SSH_HOST ?? 'host',
        username: SSH_USERNAME ?? 'username',
        tryKeyboard: true,
        privateKey: `-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----
`
    });

await ssh.dispose();

License

This project is licensed under the terms of MIT license. See the LICENSE file for more info.

Readme

Keywords

Package Sidebar

Install

npm i nodejs-ssh2

Weekly Downloads

11

Version

1.1.0

License

MIT

Unpacked Size

22 kB

Total Files

19

Last publish

Collaborators

  • macleysousa