32

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 5

18

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:

Sign up to request clarification or add additional context in comments.

5 Comments

Has the answer for this changed over two years? I would love to know if something new came up!
Not 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.
Adding to the above, these days Chrome offers a SSH client as a packaged app as well: chrome.google.com/webstore/detail/secure-shell/…
How does this answer change considering HTTP/2 is coming out? daniel.haxx.se/blog/2015/03/06/tls-in-http2
@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.
5

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.

1 Comment

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?
4

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.

1 Comment

From the readme: Before you ask, no this doesn't work on regular web pages.
1

Yes you can

  1. Install SSH server on your server

  2. Write a server side program (could be in PHP) that uses SSH client in the background

  3. 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

1 Comment

Better formatting makes your answer more clear.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.