使用端到端加密从您的浏览器中查看和控制远程终端
项目描述
什么是TermPair?
TermPair允许开发者安全地实时共享和控制终端。
您现在可以 尝试 在 https://chadsmith.dev/termpair 或 查看YouTube演示。
功能
- 实时共享Unix终端
- 从终端或浏览器输入;两者都保持同步
- 多个浏览器可以同时连接
- 浏览器权限可以是读写或只读
- 即使服务器想要,也无法读取终端数据,因为它们使用AES 128位加密
- 需要安全网络环境(https)
- 可选静态网站托管 - 自行构建Web应用程序以确保Web应用程序的完整性(示例)
- 终端的尺寸实时发送到浏览器,以确保渲染始终匹配
使用方法
首先使用 termpair serve
启动TermPair服务器,或使用已运行的https://chadsmith.dev/termpair 服务器。
服务器用于在终端和连接的浏览器之间路由加密数据 - 它实际上并不自己开始共享任何终端。
> termpair serve
现在您已启动服务器,您可以通过运行 termpair share
来共享您的终端。
此功能将您的终端连接到服务器,并允许浏览器通过服务器访问终端。
> termpair share
--------------------------------------------------------------------------------
Connection established with end-to-end encryption 🔒
Shareable link: http://localhost:8000/?terminal_id=d58ff4eed5aa9425e944abe63214382e#g8hSgHnDaBtiWKTeH4I0Ow==
Terminal ID: d58ff4eed5aa9425e944abe63214382e
Secret encryption key: g8hSgHnDaBtiWKTeH4I0Ow==
TermPair Server URL: http://localhost:8000/
Type 'exit' or close terminal to stop sharing.
--------------------------------------------------------------------------------
打印的URL包含一个唯一的终端ID和加密密钥。您可以与任何人分享这个URL。只要“termpair share”过程正在运行,任何拥有此URL的人都可以访问您的终端,因此请确保您信任您分享链接的人。
默认情况下,共享的过程是运行当前shell的新进程,由环境变量$SHELL
确定。
服务器将终端输出多播到连接到会话的所有浏览器。
系统要求
Python: 3.6+
操作系统:Linux,macOS
安装
选项1:下载可执行文件
从发布页面下载。在运行之前,您可能需要运行chmod +x
。
选项2:使用pipx
或pip
安装
您可以使用pipx进行安装,它将在隔离环境中安装Python应用程序(推荐)
> pipx install termpair
或使用pip进行安装
> pip install termpair
注意:确保您要广播的TermPair服务器与广播终端运行相同的major版本(请参阅termpair --version
)。
使用最新版本运行
您还可以使用pipx直接运行最新版本而不安装
服务
> pipx run termpair serve
然后分享
> pipx run termpair share
注意:确保您要广播的TermPair服务器与广播终端运行相同的major版本(请参阅pipx run termpair --version
)。您可以使用pipx run --spec termpair==$VERSION termpair ...
指定版本。
安全
TermPair对所有终端输入和输出使用端到端加密,这意味着服务器永远不会访问终端的原始输入或输出,也不会访问加密密钥(除了https连接)。
浏览器必须在安全上下文中运行。这通常意味着使用安全http流量(https)或在localhost上运行。
从源运行客户端
为了额外的安全保障,您可以从源广播终端。有关更多信息,请参阅CONTRIBUTING.md。
静态托管
TermPair支持静态托管JavaScript网络应用程序。这样,您可以轻松地从源运行网络应用程序,以额外的保证网络应用程序的安全性。
在这种安排中,您可以自己构建TermPair网络应用程序并托管在您的计算机上,或者静态托管在GitHub pages或Vercel等平台上。这样,您可以保证服务器不会提供恶意JavaScript网络应用程序,因为您是从源构建的。
在没有TermPair服务器运行的情况下打开网络应用程序时,您需要指定终端ID、加密密钥和TermPair服务器主机以建立连接。
您可以通过此项目的GitHub页面https://cs01.github.io/termpair/connect/尝试它或查看其外观。
有关更多信息,请参阅CONTRIBUTING.md。
工作原理
TermPair由三部分组成
- 服务器
- 终端客户端
- 在浏览器客户端中运行的JavaScript网络应用程序
服务器
首先,启动termpair服务器(termpair serve
)。服务器充当路由器,盲目地在TermPair终端客户端和连接的浏览器之间转发加密数据。服务器监听来自unix终端客户端的termpair websocket连接,并维护到任何连接浏览器的映射。
终端客户端
当用户想要共享他们的终端时,他们运行 termpair share
来启动客户端。TermPair 客户端将此会话注册到服务器,然后通过 fork 创建一个带有所需进程的伪终端(pty),通常是一个shell,如 bash
或 zsh
。TermPair 会从pty的文件描述符读取数据,然后将其写入到真实终端的stdout,就像正常打印一样。然而,它也会加密此输出并通过websocket发送到服务器。
加密
TermPair 客户端启动时创建三个128位AES加密密钥。
- 第一个用于在发送到服务器之前加密终端的输出。
- 第二个用于在发送用户输入到服务器之前由浏览器使用。
- 第三个是一个“引导”密钥,由浏览器用于解密从广播终端接收的初始连接响应,该响应包含使用此第三个密钥加密的前两个密钥。浏览器通过服务器无法访问的url的一部分获得此引导密钥,或者通过手动用户输入。由于多个浏览器可以连接到终端,所以没有使用像Diffie-Hellman这样的公钥交换,这会增加TermPair代码库的复杂性。不过,未来可能考虑以某种形式使用DH。
Web应用
TermPair客户端为用户提供唯一URL,用于共享会话期间。该URL指向TermPair Web应用(TypeScript/React),该应用设置websocket连接以接收和发送加密的终端数据。当接收到数据时,它会被解密并写入基于浏览器的终端。
当用户在浏览器终端中键入时,它会在浏览器中使用密钥#2加密,发送到服务器,然后从服务器转发到终端,然后在终端由TermPair解密。最后,TermPair客户端将其写入pty的文件描述符,就像直接键入到终端一样。
当任一密钥发送2^20(1048576)条消息后,AES密钥#1和#2会进行轮换。AES初始化向量(IV)值单调递增,以确保它们永远不会被重复使用。
使用NGINX提供服务
以下配置可以用于在nginx代理后面运行。
TermPair服务器必须已经启动。这通常是通过systemd服务完成的。正在运行的端口号必须在upstream
配置中指定。
upstream termpair_app {
# Make sure the port matches the port you are running on
server 127.0.0.1:8000;
}
server {
server_name myserver.com;
# I recommend Certbot if you don't have SSL set up
listen 443 ssl;
ssl_certificate fullchain.pem;
ssl_certificate_key privkey.pem;
location /termpair/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://termpair_app/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
作为systemd服务运行
如果您使用systemd管理服务,以下是一个您可以开始的示例配置。
此配置假设您已将TermPair安装到/home/$USER/.local/bin/termpair
,并将文件保存到/etc/systemd/system/termpair.service
。
# /etc/systemd/system/termpair.service
# https://www.freedesktop.org/software/systemd/man/systemd.service.html
[Unit]
Description=
After=network.target
[Service]
User=$USER
Group=www-data
WorkingDirectory=/var/www/termpair/
PermissionsStartOnly=true
ExecStart=/home/$USER/.local/bin/termpair serve --port 8000
ExecStop=
Restart=on-failure
RestartSec=1s
[Install]
WantedBy=multi-user.target
保存后,您可以使用systemctl
启动您的systemd
服务
sudo systemctl daemon-reload
sudo systemctl enable termpair.service
sudo systemctl restart termpair
CLI API
> termpair --help
usage: termpair [-h] [--version] {share,serve} ...
View and control remote terminals from your browser
positional arguments:
{share,serve}
optional arguments:
-h, --help show this help message and exit
--version
启动TermPair服务器
> termpair serve --help
usage: termpair serve [-h] [--port PORT] [--host HOST] [--certfile CERTFILE]
[--keyfile KEYFILE]
Run termpair server to route messages between unix terminals and browsers. Run
this before connecting any clients. It is recommended to encrypt communication
by using SSL/TLS. To generate an SSL certificate and private key, run `openssl
req -newkey rsa:2048 -nodes -keyout host.key -x509 -days 365 -out host.crt`.
To skip questions and use defaults, add the `-batch` flag. You can ignore
warnings about self-signed certificates since you know you just made it. Then
use them, pass the '--certfile' and '--keyfile' arguments.
optional arguments:
-h, --help show this help message and exit
--port PORT, -p PORT Port to run the server on (default: 8000)
--host HOST Host to run the server on (0.0.0.0 exposes publicly)
(default: localhost)
--certfile CERTFILE, -c CERTFILE
Path to SSL certificate file (commonly .crt extension)
(default: None)
--keyfile KEYFILE, -k KEYFILE
Path to SSL private key .key file (commonly .key
extension) (default: None)
使用TermPair客户端共享终端
> termpair share --help
usage: termpair share [-h] [--cmd CMD] [--port PORT] [--host HOST] [--read-only]
[--open-browser]
Share your terminal session with one or more browsers. A termpair server must be
running before using this command.
optional arguments:
-h, --help show this help message and exit
--cmd CMD The command to run in this TermPair session. Defaults to
the SHELL environment variable (default: /bin/bash)
--port PORT, -p PORT port server is running on (default: 8000)
--host HOST host server is running on (default: http://localhost)
--read-only, -r Do not allow browsers to write to the terminal (default:
False)
--open-browser, -b Open a browser tab to the terminal after you start
sharing (default: False)
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分发
构建分发的
termpair-0.3.1.5.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 34f914e4910bf4cc88b3f85b1a16e8aa4d9170d66cb6f97914adbb9f13881174 |
|
MD5 | d5c1d3ee375361ac8618898f965b6264 |
|
BLAKE2b-256 | 592d05402d0ce01c89f94d49a26ac44f0352f84c9e17c27fb9dbeb0b1e24cc74 |
termpair-0.3.1.5-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ff649c9f93facccf5c31580be101e0025f92a6585fbf8f1a66c74512537bc4f3 |
|
MD5 | a612b08c98b85e6496c1fbe8ab3f801c |
|
BLAKE2b-256 | 2363ef15ed50cb5850fba10a5edbb2f588560d537cf500799733feff782e030c |