Skip to main content

View and control remote terminals from your browser with end-to-end encryption

Project description

View and control remote terminals from your browser with end-to-end encryption

Documentation: https://cs01.github.io/termpair

Source Code: https://github.com/cs01/termpair

Try It: https://chadsmith.dev/termpair

PyPI version PyPI version

What is TermPair?

TermPair lets developers securely share and control terminals in real time.

Usage

First start the TermPair server with termpair serve, or use the one already running at https://chadsmith.dev/termpair.

The server is used to route encrypted data between terminals and connected browsers.

> termpair serve --port 8000
INFO:     Started server process [25289]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://localhost:8000 (Press CTRL+C to quit)
INFO:     ('127.0.0.1', 51924) - "WebSocket /connect_to_terminal" [accepted]

Then share your terminal by running termpair share.

This connects your terminal to the server, and allows browsers to access the terminal.

> termpair share --port 8000
--------------------------------------------------------------------------------
Connection established with end-to-end encryption 🔒
Sharing '/bin/bash' at

http://localhost:8000/?terminal_id=fd96c0f84adc6be776872950e19caecc#GyMlK2LLTqvoyTNzJ+qwLg==

Type 'exit' or close terminal to stop sharing.
--------------------------------------------------------------------------------

The URL printed contains a unique terminal ID and an encryption key. You can share that URL with whoever you want. Anyone who has it can access your terminal while the termpair share process is running.

The server multicasts terminal output to all browsers that connect to the session.

Security

TermPair uses 128 bit end-to-end encryption for all terminal input and output.

The browser must be running in a secure context. This typically means running on localhost, or with secure http traffic (https).

How it Works

TermPair consists of three pieces:

  1. terminal client
  2. server
  3. browser client(s)

First, the termpair server is started (termpair serve). The server acts as a router that blindly forwards encrypted data between TermPair terminal clients and connected browsers.

It listens for termpair websocket connections from unix terminal clients, and maintains a mapping to any connected browsers.

Before the TermPair client sends terminal output to the server, it encrypts it using a secret key so the server cannot read it. The server forwards that data to connected browsers. When the browsers receive the data, they use the secret key to decrypt and display the terminal output. The browser obtains the secret key via a part of the url that is not sent to the server.

Likewise, when a browser sends input to the terminal, it is encrypted in the browser, forwarded from the server to the terminal, then decrypted in the terminal by TermPair, and finally written to the terminal's input.

Run With Latest Version

Use pipx to run the latest version without installing:

Serve:

> pipx run termpair serve

Then share:

> pipx run termpair share --open-browser

Note: pipx caches installations for a few days. To ignore the cache and force a fresh installation, use pipx run --no-cache termpair ....

Installation

You can install using pipx:

> pipx install termpair

or install with pip

> pip install termpair

Serving with NGINX

Running behind an nginx proxy can be done with the following configuration.

The TermPair server must be started with termpair serve, and the port being run on must be specified in the upstream configuration.

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";
    }
}

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

To start the TermPair server:

> 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)

To share a terminal using the TermPair client:

> termpair share --help
usage: termpair share [-h] [--cmd CMD] [--port PORT] [--host HOST]
                      [--no-browser-control] [--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: None)
  --host HOST           host server is running on (default: http://localhost)
  --no-browser-control, -n
                        Do not allow browsers to control your terminal
                        remotely (default: False)
  --open-browser, -b    Open a browser tab to the terminal after you start
                        sharing (default: False)

System Requirements

Python: 3.6+

Operating System:

  • To view/control from the browser: All operating systems are supported.
  • To run the server, termpair serve: Tested on Linux. Should work on macOS. Might work on Windows.
  • To share your terminal, termpair share: Tested on Linux. Should work on macOS. Probably doesn't work on Windows.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

termpair-0.2.0.0.tar.gz (687.7 kB view details)

Uploaded Source

Built Distribution

termpair-0.2.0.0-py3-none-any.whl (692.4 kB view details)

Uploaded Python 3

File details

Details for the file termpair-0.2.0.0.tar.gz.

File metadata

  • Download URL: termpair-0.2.0.0.tar.gz
  • Upload date:
  • Size: 687.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.9

File hashes

Hashes for termpair-0.2.0.0.tar.gz
Algorithm Hash digest
SHA256 6701dd452d839b5e85065c3d35251a1bc9ce5285a6c4fefd6c74c5e1873969e8
MD5 a721b516a508147fe92bae850300e952
BLAKE2b-256 76c78f9e7bd8cf7e90a8356609aa8f4419da3497e9843489c98a6f7acdaba8d8

See more details on using hashes here.

File details

Details for the file termpair-0.2.0.0-py3-none-any.whl.

File metadata

  • Download URL: termpair-0.2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 692.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.9

File hashes

Hashes for termpair-0.2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 80d02b03f2be83da8f1b0709704dde5b266a76220f67913eb5e0233ee5dd8427
MD5 1b6baa5b6a98dc1902ca7bf3c6c9e0cc
BLAKE2b-256 2bf1e88331b2b53cc319d7c61c272f2b230e21372872b183d4de622d60e2de83

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page