SSH client for Node.js [closed]
Asked Answered
V

4

44

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

Vaporization answered 3/3, 2011 at 12:58 Comment(0)
D
39

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

Downstroke answered 23/11, 2012 at 13:10 Comment(2)
It really works. I can login via ssh to my Cisco router and execute commands.Gird
What do you think of this wrapper github.com/steelbrain/node-sshSilverstein
D
17

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.

Downstroke answered 20/3, 2012 at 13:55 Comment(0)
M
12

Here are two other options:

The client is pretty solid and basic for general use. Node-control is more suited for parallel, async control over many machines (i.e. sys-admin work).

Maramarabel answered 13/4, 2011 at 18:48 Comment(3)
Have you noticed that my Nickname is a part of the URL? ^^ The client code is mine.Vaporization
@VanCoding lol haha. Always funny when someone answers with something you wrote.Mohamedmohammad
@VanCoding - What was the purpose of your question if you've written this already?Mabellemable
C
3

Much like with sftp in your earlier question, you could perhaps use the ssh client via a child process.

Cod answered 3/3, 2011 at 21:25 Comment(2)
Ok I'll try it with that. Thanks!Vaporization
Scraping command line tools works, but is a very fragile interface. An actual NPM module would be much more reliable.Tacket

© 2022 - 2024 — McMap. All rights reserved.