Is there a SSH client for node.js I could use to communicate with a server?
SSH client for Node.js [closed]
Asked Answered
An SSH2 client module written in pure JavaScript for node.js
https://github.com/mscdex/ssh2
Also checkout this wrapper for it
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-ssh –
Silverstein
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.
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).
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
Much like with sftp in your earlier question, you could perhaps use the ssh client via a child process.
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.