是否可以使用 JavaScript 连接到 SSH?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3897649/
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
Is it possible to connect to SSH using JavaScript?
提问by pathikrit
I know there is an implementation of VNC using WebSockets (http://novnc.com) but that still requires a server. I am looking to create a simple client-side JavaScript only (no Flash) connection to a port running SSH. I am guessing WebSockets is the only way to go since it does TCP. Any example code? Any other way?
我知道有一个使用 WebSockets (http://novnc.com) 的 VNC 实现,但这仍然需要一个服务器。我希望创建一个简单的客户端 JavaScript(无 Flash)连接到运行 SSH 的端口。我猜 WebSockets 是唯一的出路,因为它支持 TCP。任何示例代码?还有什么办法吗?
采纳答案by kanaka
Sorry, given your constraints (client-side Javascript only), there is no way to connect to a plain old SSH server.
抱歉,鉴于您的限制(仅限客户端 Javascript),无法连接到普通的旧 SSH 服务器。
WebSockets is not plain TCP. It's a framed protocol with a HTTP-like handshake between the client and server that includes origin policy.
WebSockets 不是普通的 TCP。它是一个框架协议,在客户端和服务器之间进行类似 HTTP 的握手,包括源策略。
Flash can make plain TCP connections, but it also has origin policy enforcement. The way it does this is by making a connection to the same server on port 843 and asking for a special XML file that contains the origin policy. If you are willing to relax your constraints slightly such that you are willing to run a generic WebSockets to TCP proxy either on a server (any server) or on the client then you can do what you are wanting to do. noVNC includes a C and python WebSockets to TCP proxy: http://github.com/kanaka/noVNC/tree/master/utils/.
Flash 可以建立普通的 TCP 连接,但它也有源策略执行。这样做的方法是通过端口 843 连接到同一台服务器,并请求一个包含源策略的特殊 XML 文件。如果您愿意稍微放宽您的限制,以便您愿意在服务器(任何服务器)或客户端上运行通用 WebSockets 到 TCP 代理,那么您可以做您想做的事情。noVNC 包括一个 C 和 python WebSockets 到 TCP 代理:http: //github.com/kanaka/noVNC/tree/master/utils/。
Other info you might find useful:
您可能会觉得有用的其他信息:
Current WebSocket draft: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
Simple (insecure) way of running a flash policy server (Linux/UNIX with socat) is described here: http://github.com/kanaka/noVNC/blob/master/docs/flash_policy.txt
More info about the flash policy file: http://code.google.com/p/doctype/wiki/ArticleFlashSecurity
当前的 WebSocket 草案:http: //tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
此处描述了运行闪存策略服务器(带有 socat 的 Linux/UNIX)的简单(不安全)方式:http: //github.com/kanaka/noVNC/blob/master/docs/flash_policy.txt
有关 Flash 策略文件的更多信息:http: //code.google.com/p/doctype/wiki/ArticleFlashSecurity
回答by Nathan Appere
For those still searching, paramikojscould be the answer.
对于那些仍在搜索的人来说,paramikojs可能是答案。
I'm currently having a similar issue:I need a SSH JS client-side implementation, and I need it to be BSD licensed. Alas paramikojs seems to be GPL licensed.
我目前遇到了类似的问题:我需要一个 SSH JS 客户端实现,并且我需要它获得 BSD 许可。唉 paramikojs 似乎是 GPL 许可的。
回答by Colin Hebert
You can take a look at serfish. It's a solution to access a SSH server. But if you're hosting your web application on the same server as your ssh, there are other solutions such as shell in a box.
你可以看看serfish。这是访问SSH服务器的解决方案。但是,如果您将 Web 应用程序与 ssh 托管在同一台服务器上,那么还有其他解决方案,例如shell in a box。
回答by Jun
It's definitely possible using a Linux emulator with full network support like the great OpenRISC emulator jor1k.
绝对可以使用具有完整网络支持的 Linux 模拟器,例如出色的 OpenRISC 模拟器jor1k。
Note that I've created browser-tools.net, a collection of in-browser tools from number of different projects.
请注意,我已经创建了browser-tools.net,这是来自多个不同项目的浏览器内工具的集合。