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?
5 Answers
Sorry, given your constraints (client-side Javascript only), there is no way to connect to a plain old SSH server.
WebSockets is not plain TCP. It's a framed protocol with a HTTP-like handshake between the client and server that includes origin policy.
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/.
Other info you might find useful:
Current WebSocket draft: https://datatracker.ietf.org/doc/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
-
2Has the answer for this changed over two years? I would love to know if something new came up!– DannySep 18, 2012 at 8:12
-
2Not for plain web apps. However, Chrome packaged apps now support raw TCP/UDP sockets: developer.chrome.com/apps/app_network.html For example, they have an example telnet client: github.com/GoogleChrome/chrome-app-samples/tree/master/telnet You could extend the telnet example to add encryption and key management to create an ssh app. But this would be limited to Chrome packaged apps and not a generic web app.– kanakaSep 18, 2012 at 13:34
-
2Adding to the above, these days Chrome offers a SSH client as a packaged app as well: chrome.google.com/webstore/detail/secure-shell/… Jan 27, 2014 at 20:16
-
How does this answer change considering HTTP/2 is coming out? daniel.haxx.se/blog/2015/03/06/tls-in-http2 Mar 6, 2015 at 20:01
-
1@wrick sorry, HTTP/2 hasn't changed the answer. You still need some way to bridge between a protocol that your browser speaks (http, http2, websocks, webrtc) and the SSH protocol.– kanakaMar 7, 2015 at 14:58
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 uses a server to tunnel commands typed in the browser to the ssh host. shellinabox similarly needs to run on the host for the front-end browser-terminal to work. Is there anyway to emulate the terminal on client-side using JS only without writing any server (or ssh host) side code? Oct 10, 2010 at 1:17
For those still searching, paramikojs could be the answer.
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.
-
4
Yes you can
Install SSH server on your server
Write a server side program (could be in PHP) that uses SSH client in the background
Redirect messages between the SSH client (that probably has been residing in the same server as SSH server) and the JavaScript program in the web browser other side of the internet.
That server side program acts like a postman only and the java script program in the browser is just another postman between the user and server program.
(SSH server)<->(SSH client)<->(PHP e.g)<->(JavaScript)
Also don't forget that in the JavaScript program could have use Ajax for better mechanism. Also SSH client might be not completely and absolutely necessary because that PHP server side program could directly connect to SSH server
It's definitely possible using a Linux emulator with full network support like the great OpenRISC emulator jor1k.
Note that I've created browser-tools.net, a collection of in-browser tools from number of different projects.