ssh-repl

SSH into your node.js process and access a REPL

Usage no npm install needed!

<script type="module">
  import sshRepl from 'https://cdn.skypack.dev/ssh-repl';
</script>

README

Description

SSH into your node.js process and access a REPL.

Requirements

Install

npm install ssh-repl

Example

const fs = require('fs');

const sshrepl = require('ssh-repl');

const repl = sshrepl({
  server: {
    hostKeys: [ fs.readFileSync('host.key') ]
  },
  users: {
    foo: {
      publicKey: fs.readFileSync('foo-key.pub'),
      repl: { prompt: 'foo> ' }
    },
    bar: {
      password: 'baz',
      repl: { prompt: 'bar> ' }
    }
  },
  port: 2244
}, function() {
  console.log('SSH REPL listening');
});

// Call `repl.close()` to stop listening

API

require('ssh-repl') returns a function that creates and starts an SSH REPL. It has the signature:

  • (< object >config[, < function >callback]) - object - Creates and starts an SSH REPL. The object returned contains a .close() method to stop the server. It accepts an optional callback that is called when the server is closed. config can contain:

    • server - object - The configuration for the SSH server. See the ssh2 documentation for a list of supported properties.

    • port - integer - Port number to listen on.

    • users - mixed - The user configuration. This is used to both authenticate users and to optionally pass settings to repl.start(). If users is a function, it is passed two arguments: (< string >username, < function >callback), where callback has the signature (< Error >err, < object >userConfig). If users is an object, it should be keyed on username, with the value being the user configuration. Allowed user configuration properties:

      • One of two authentication methods is required:

        • password - string - The password for the user.

        • publicKey - mixed - The public key for the user. This value can be a Buffer instance or a string.

      • repl - object - If supplied, the properties on this object are passed on to repl.start().

    If callback is supplied, it is called once the SSH REPL is listening for incoming connections. It has the signature (< Error >err, < number >boundPort). The boundPort argument is useful when binding on port 0.