Giter VIP home page Giter VIP logo

ssh2-auth's Introduction

ssh2-auth

A wrapper over ssh2's client module to handle the authentication step.

Installation

npm install ssh2-auth

Usage

Simplest use case, just provide the hostname as a string, with user and port if they are not the default ones. In this example we are relying on the default user's public keys for the authentication (~/.ssh/id_dsa, ~/.ssh/id_ecdsa, ~/.ssh/id_rsa).

var ssh2auth = require('ssh2-auth');

ssh2auth('[email protected]:2222', function(err, conn) {
    if (err) return console.log(err);
    var command = 'echo hey there, im $(whoami) at $(hostname)';
    conn.exec(command, function(err, proc) {
        proc.stdout.pipe(process.stdout);
        proc.on('close', function() {
            conn.end();
        });
    });
});

Authentication with the provided password, for the current user and default port (port 22):

ssh2auth({ host: 'example.com', password: 'secret' }, function(err, conn) {
    if (err) return console.log(err);
    var command = 'echo hey there, im $(whoami) at $(hostname)';
    conn.exec(command, function(err, proc) {
        proc.stdout.pipe(process.stdout);
        proc.on('close', function() {
            conn.end();
        });
    });
});

Public key authentication with the identity file in a custom location:

ssh2auth({
    host: 'example.com',
    port: 'port',
    user: 'user',
    // can be an array of key paths instead, to try them until one of them succeeds
    privateKey: '/path/to/key.pem'
}, function(err, conn) {
    // ...
});

License

MIT license - http://www.opensource.org/licenses/mit-license.php

ssh2-auth's People

Contributors

dgoguerra avatar

Watchers

James Cloos avatar  avatar

ssh2-auth's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.