SSH client for Node.js


Question

Is there a SSH client for node.js I could use to communicate with a server?

1
40
3/3/2011 12:58:26 PM

Accepted Answer

An SSH2 client module written in pure JavaScript for node.js

https://github.com/mscdex/ssh2

Also checkout this wrapper for it

https://github.com/mikeal/sequest

36
11/19/2014 8:39:07 PM

Node.js child processes won't do if you need to use a password for login, because OpenSSH client does not read the password from stdin, but from a pseudo terminal.

You can work around this by using pty.js:

var pty = require("pty.js");
var term = pty.spawn("ssh", ["username@localhost", "whoami"]);

term.on("data", function(data) {
  console.log("Incoming: " + data.toString());
});

// Wait a sec before sending the password. For proper implementation 
// you should wait for the password prompt.
setTimeout(function(){
  term.write("mypassword\n");
}, 1000);

This being said, you should always use SSH key pairs for this if possible.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon