如何使用xterm.js创建基于Web的终端以SSH进入本地网络上的系统 [英] How to create web based terminal using xterm.js to ssh into a system on local network

查看:1438
本文介绍了如何使用xterm.js创建基于Web的终端以SSH进入本地网络上的系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个很棒的库 xterm.js ,它也是Visual Studio Code终端的基础.我有一个非常笼统的问题.

I came across this awesome library xterm.js which is also the base for Visual Studio Code's terminal. I have a very general question.

我想通过基于Web的终端(不在网络中,可能在aws服务器上)访问本地网络上的机器(通过ssh进入机器).我能够在本地网络中成功完成此操作,但无法从Internet->本地网络中得出结论.

I want to access a machine(ssh into a machine ) on a local network through a web based terminal(which is out of network, may be on a aws server). I was able to do this in a local network successfully but I could not reach to a conclusion to do it from Internet-->local network .

例如-An aws server running the application on ip 54.123.11.98 which has a GUI with a button to open terminal. I want to open terminal of a local machine which is in a local network somewhere behind some public ip on local ip 192.168.1.7.

上面的示例可以使用某种解决方案来实现,在该解决方案中,我可以使用xterm.js,这样就不必构建基于Web的终端了?以这种方式暴露终端时,我应该牢记的主要安全问题是什么?

我一直在考虑在AWS和本地网络ip之间使用固定的中间服务器,并使用某种反向ssh隧道过程来执行此操作,但是我不确定这是否是正确的方法,或者是否有更简单的方法/更好的方法来实现这一目标.

I was thinking in line with using a fixed intermediate server between AWS and local network ip and use some sort of reverse ssh tunnel process to do this but I am not sure if this is the right way or could there be a more simple/better way to achieve this.

我知道数字海洋,谷歌云,他们都可以做到这一点,但是当我在本地网络中有一台机器时,它们必须连接到具有公共IP的计算机.我真的不想配置路由器以进行任何类型的设置.

I know digital ocean, google cloud , they all do this but they have to connect to a computer which has public ip while I have a machine in a local network. I don't really want to configure router to do any kind of setup .

推荐答案

经过一番研究,这里是有效的代码.

After a bit of research here is working code.

图书馆:

1) https://socket.io/

此库用于将软件包从客户端传输到服务器.

This library is used for transmit package from client to server.

2) https://github.com/staltz/xstream

此库用于终端视图.

3) https://github.com/mscdex/ssh2

这是用于与远程服务器建立连接的主要库.

This is the main library which is used for establishing a connection with your remote server.

第1步:将Library 3安装到您的项目文件夹中

Step 1: Install Library 3 into your project folder

第2步:从节点侧开始,为打开的套接字创建server.js文件

Step 2: Start from node side create a server.js file for open socket

第3步: 将客户端套接字连接到节点服务器(均在本地计算机中)

Step 3: Connection client socket to node server (both are in local machine)

棘手的逻辑是如何使用套接字和ssh2.

The tricky logic is how to use socket and ssh2.

释放套接字时,您需要使用ssh2库触发SSH命令.根据ssh2库的响应(来自服务器),您需要将套接字包传输到客户端.就是这样.

On emission of socket you need to trigger an SSH command using the ssh2 library. On response of the ssh2 library (from server) you need to transmit the socket package to the client. That's it.

点击此处以找到示例.

该示例将包含这些文件&文件夹:

That example will have these files & folders:

Type    Name
------------
FILE    server.js
FILE    package.json
FOLDER  src
FOLDER  xtream

首先,您需要在server.js上配置服务器IP,用户名和密码或cert文件,然后运行node server.js.

First you need to configure your server IP, user and password or cert file on server.js and just run node server.js.

P.S .:不要忘记运行npm install

P.S.: Don't forget to run npm install

让我知道您是否有任何疑问!

Let me know if you have any questions!

这篇关于如何使用xterm.js创建基于Web的终端以SSH进入本地网络上的系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆