Javascript Node.js 的 SSH 客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5180981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SSH client for Node.js
提问by Van Coding
Is there a SSH client for node.js I could use to communicate with a server?
是否有 node.js 的 SSH 客户端可以用来与服务器通信?
采纳答案by Epeli
An SSH2 client module written in pure JavaScript for node.js
用纯 JavaScript 为 node.js 编写的 SSH2 客户端模块
https://github.com/mscdex/ssh2
https://github.com/mscdex/ssh2
Also checkout this wrapper for it
还要检查这个包装器
回答by Epeli
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.
如果您需要使用密码登录,Node.js 子进程将不会这样做,因为 OpenSSH 客户端不会从 stdin 读取密码,而是从伪终端读取密码。
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.
话虽如此,如果可能,您应该始终为此使用 SSH 密钥对。
回答by Van Nguyen
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).
客户端对于一般用途来说非常可靠和基本。节点控制更适合于对多台机器的并行、异步控制(即系统管理工作)。
回答by Greg
Much like with sftp in your earlier question, you could perhaps use the ssh client via a child process.