Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-ssh

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-ssh

A wrapper for ssh2 to make it easier to perform commands over SSH

  • 0.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.7K
increased by1.07%
Maintainers
1
Weekly downloads
 
Created
Source

simple-ssh

A wrapper for the ssh2 client module by Brian White which makes it easier to run a sequence of commands over SSH.

Requirements

  • node.js -- v0.8.7 or newer

Install

npm install simple-ssh

Examples

  • Echoing out a users PATH:
var SSH = require('simple-ssh');

var ssh = new SSH({
    host: 'localhost',
    user: 'username',
    pass: 'password'
});

ssh.exec('echo $PATH', {
    out: function(stdout) {
        console.log(stdout);
    }
}).start();

/*** Using the `args` options instead ***/
ssh.exec('echo', {
    args: ['$PATH'],
    out: function(stdout) {
        console.log(stdout);
    }
}).start();
  • Capturing error output:
ssh.exec('this-does-not-exist', {
    err: function(stderr) {
        console.log(stderr); // this-does-not-exist: command not found
    }
}).start();
  • Capturing error codes:
ssh.exec('exit 69', {
    exit: function(code) {
        console.log(code); // 69
    }
}).start();
  • Chaining commands together:
ssh
    .exec('echo "Node.js"', {
        out: console.log
    })
    .exec('echo "is"', {
        out: console.log
    })
    .exec('echo "awesome!"', {
        out: console.log
    })
    .start();

// Output:
// Node.js
// is
// awesome!
  • Running a command using sudo
ssh.exec('sudo echo "Pseudo-sudo"', {
    pty: true,
    out: console.log
}).start();

API

Functions

  • Constructor( [ config ] )

    • config { Object }:
      • config.host { String }: Hostname
      • config.port { Number }: Port number (default: 22)
      • config.user { String }: Username
      • config.pass { String }: Password
  • exec( command, [ options ] ): Adds a command to the stack

    • command { String }: Command to be executed
    • options { Object }:
      • options.args { String[] }: Additional command line arguments (default: null)
      • options.out { Function( stdout ) }: stdout handler
        • stdout { String }: Output streamed through stdout
      • options.err { Function( stderr ) }: stderr handler
        • stderr { String }: Output stream through stderr
      • options.exit { Function( code ) }: Exit handler
        • code { Number }: Exit code
      • options.pty { Boolean }: Allocates a pseudo-tty, useful for command which require sudo (default: false)
  • start( [ options ] ): Starts executing the commands

    • options { Object }:
      • options.success { Function() }: Called on successful connection
      • options.fail { Function(err) }: Called if the connection failed
        • err { Error }: Error information
  • end() ** Ends the SSH session**

Keywords

FAQs

Package last updated on 14 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc