upterm
A tool for developers to share terminal/tmux sessions securely over the web. It’s perfect for remote pair programming, accessing computers behind NATs/firewalls, remote debugging, and more
About upterm
This large README is shown as a plain-text preview. Read the full README at the source
# Upterm [Upterm](https://github.com/owenthereal/upterm) lets you reach a terminal over SSH without opening an inbound port. - **Check on an AI agent from your phone.** Leave the agent running in Herdr on your home machine. When it needs approval, connect through Upterm from your phone or another laptop. Each connection opens its own Herdr client, and Herdr keeps the agent running when you disconnect. [Set up remote access to Herdr][herdr-guide]. - **Debug a failing test with a teammate.** Run `upterm host` and send your teammate the join command. You can both type in the same terminal, rerun the test, and inspect the failure together. [Share a terminal](https://github.com/owenthereal/upterm#wrench-basic-usage). [herdr-guide]: https://github.com/owenthereal/upterm/blob/master/guides/herdr.md This is a [blog post](https://owenou.com/upterm) to describe Upterm in depth. ## :movie_camera: Quick Demo [](https://asciinema.org/a/efeKPxxzKi3pkyu9LWs1yqdbB) ## :rocket: Getting Started ## Installation ### Mac ```console brew install --cask owenthereal/upterm/upterm ``` #### Migrating from Formula to Cask If you previously installed upterm using the Homebrew formula (without `--cask`), you'll need to migrate to the Cask version: ```console # Uninstall the old formula version brew uninstall upterm # Install the new Cask version brew install --cask owenthereal/upterm/upterm ``` **Note:** Running `brew upgrade` with the old formula installed will fail with an error. Follow the migration steps above to resolve this. ### Windows ```powershell scoop bucket add upterm https://github.com/owenthereal/scoop-upterm scoop install upterm ``` ### Standalone `upterm` can be easily installed as an executable. Download the latest [compiled binaries](https://github.com/owenthereal/upterm/releases) and put it in your executable path. ### Go ```console go install github.com/owenthereal/upterm/cmd/upterm@latest ``` ### From source ```console git clone https://github.com/owenthereal/upterm.git cd upterm go install ./cmd/upterm/... ``` ## :wrench: Basic Usage 1. Host starts a terminal session: ```console upterm host ``` 1. Host retrieves and shares the connection string: ```console upterm session current ``` 1. Client joins using the shared string, and rejoins on its own if the connection drops: ```console upterm join ssh://[email protected] ``` Or with plain `ssh` (no install needed): ```console ssh [email protected] ``` `SESSION_USER` stands for the session's SSH user, the part before `@` on the host's `➤ SSH:` line. On uptermd.upterm.dev it is the session ID; a self-hosted relay that routes without Consul adds the node the session is on, after a colon. To reach a session by a name of your own instead, see [Reach your own machine](#reach-your-own-machine). ## :blue_book: Quick Reference Dive into more commands and advanced usage in the [documentation](docs/upterm.md). To reach your own machine from a laptop or a phone with plain `ssh`, VS Code or `scp`, see [Reach your own machine](#reach-your-own-machine). Below are some notable highlights: ### Joining with `upterm join` `upterm join` takes the connect string on the host's `➤ Join:` line. If the connection drops, it resets most terminal modes the session had set (the alternate screen and mouse reporting, for example), says why it's waiting, and rejoins on its own: Enter retries at once, and Ctrl-C stops. `~.` leaves. A forced command (`upterm host --force-command`) starts again on each rejoin, so don't use `upterm join` with one whose effects mustn't repeat. It offers keys as `ssh` does: the agent's, then the default key files, and it generates one only when you have none. Unlike `ssh`, it doesn't read `~/.ssh/config`: per-host `IdentityFile`, `User` and `ProxyJump` don't apply, the target can't be a host alias, and FIDO keys work only through the agent. Use `-i`, or plain `ssh`, for those. ### Command Execution Host a session with any desired command: ```console upterm host -- docker run --rm -ti ubuntu bash ``` ### Access Control Host a session with specified client public key(s) authorized to connect: ```console upterm host --authorized-keys PATH_TO_PUBLIC_KEY ``` Or authorize users by `provider:username`, fetching their public keys from a code-hosting service: ```console upterm host --authorized-user github:username upterm host --authorized-user gitlab:username upterm host --authorized-user srht:username upterm host --authorized-user codeberg:username ``` Self-hosted instances are supported by naming the host. `gitea` and `forgejo` always require one, since there is no default instance. Keys are always fetched over HTTPS: ```console upterm host --authorized-user github:[email protected] upterm host --authorized-user gitea:[email protected] upterm host --authorized-user forgejo:[email protected] upterm host --authorized-user https://git.example.com/username ``` For a GitHub Enterprise Server instance that requires a login, authenticate first with `gh auth login --hostname ghe.example.com`; only credentials stored for that host are used. ### SSH agents and hardware keys `upterm host` authenticates to the server with your SSH identity when the tunnel is established, the same as `ssh` would, and again whenever it reconnects. Everything else — guest joins, `upterm attach`, key renegotiation — uses a key generated for the session, so an agent that confirms each signature (gpg-agent with a smartcard, 1Password, a FIDO key) asks at start. On a server that accepts any host, as uptermd.upterm.dev does, a reconnect uses the session's own key and doesn't ask the agent, unless `--private-key` names the identities: those are then the only ones offered, on every reconnect too. On a server with `--authorized-keys`, such an agent asks on every reconnect. For a long-lived session that will reconnect, use a key file or an agent without per-use confirmation. To keep such an agent out of it entirely, name a plain key. A supplied `--private-key` is the whole set, like OpenSSH's `IdentitiesOnly`: ```console ssh-keygen -t ed25519 -N '' -f ~/.ssh/upterm upterm host --private-key ~/.ssh/upterm ``` To use one particular agent identity, name its public key: ```console upterm host --private-key ~/.ssh/id_ed25519_sk.pub ``` Guests still authenticate with a key of their own. A session with no `--authorized-keys` or `--authorized-user` accepts any key, but not none. Started with `--accept` as well, such a session is open: anyone with the session ID can join, and nobody is asked. `upterm host` warns about it as the session starts, and `upterm session info` says so (`"open": true` in its JSON). ### Force command Host a session initiating `tmux new -t pair-programming`, while ensuring clients join with `tmux attach -t pair-programming`. This mirrors functionality provided by tmate: ```console upterm host --force-command 'tmux attach -t pair-programming' -- tmux new -t pair-programming ``` A forced command starts again each time `upterm join` rejoins; nothing the previous one did is undone. Each guest's forced command runs on a pty of its own, with `SSH_TTY`, `SSH_CONNECTION` and `SSH_CLIENT` set as sshd sets them, so a program that copies over OSC 52 when it runs over SSH copies to the guest's clipboard. `--hide-client-ip` leaves out the two that carry the guest's address. ### Running Without a Terminal Host a session from a script or CI step with nothing attached to its terminal. `--accept` skips the confirmation prompt, `--name` gives the session a local name you choose, and `--pty-size` pins the terminal geometry so the command renders the same for every client: ```console upterm host --accept --name build-shell --pty-size 132x43 -- bash & ``` In a fresh environment `known_hosts` does not yet hold the relay's key, and the host-key confirmation cannot be answered without a terminal. Pin it directly: ```console mkdir -p ~/.ssh && cat >> ~/.ssh/known_hosts <<'EOF' @cert-authority uptermd.upterm.dev ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICiecex8Dq718eSe1CCLgLvDmI7AagvCtax7brPFWkh4 @cert-authority [uptermd.upterm.dev]:443 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICiecex8Dq718eSe1CCLgLvDmI7AagvCtax7brPFWkh4 EOF ``` The same two lines are committed at [`etc/known_hosts/uptermd.upterm.dev`](etc/known_hosts/uptermd.upterm.dev), for anyone who would rather fetch the file than paste it — compare the fingerprint of *every* line in whatever you fetch before trusting it. `uptermd.upterm.dev`'s host key has the SHA256 fingerprint `SHA256:9ajV8JqMe6jJE/s3TYjb/9xw7T0pfJ2+gADiBIJWDPE`; that's the value to check against, however you obtained the key. Note that `ssh-keyscan uptermd.upterm.dev` is **not** a substitute. It records whatever answered the scan, so its line is only as good as the fingerprint check you make on it. The relay presents an SSH host certificate signed with its own key, and upterm checks the plain key line `ssh-keyscan` emits against that key, as OpenSSH does; upterm 0.37.0 and earlier authorize a certificate only through a line marked `@cert-authority`, and fall back to the first-connection prompt, which a runner with no terminal can't answer. `--skip-host-key-check` accepts whatever answers on the first connection. It is convenient for a self-hosted relay you are bringing up, and it is not a substitute for pinning: on a fresh runner it will trust anything that can intercept that connection. If this key is ever rotated, a pin pasted into a job has to be updated by hand: the fingerprint here changes, and so does the copy bundled with [action-upterm](https://github.com/owenthereal/action-upterm), which needs a release of its own. A stale pin surfaces as a host-key mismatch, and upterm won't connect until it is updated. upterm 0.37.0 and earlier treat it as an unknown host instead: a job with no terminal fails, because the first-connection prompt cannot be answered, and an interactive run is prompted and could accept the new key, so update the pin rather than accepting at the prompt. Watch this section after upgrading. Look the session up by name while it runs and after it ends. The record outlives the process and carries how the command finished: ```console upterm session info build-shell -o json ``` The `status` field is `starting`, `ready`, `reconnecting`, `disconnected` or `ending` while the session still holds its name, and `ended` once nobody does; `reason` is `exited` (with `exitCode`), `signaled` (with `signal` and originating `signalNumber`), `stopped` (explicit admin stop), `canceled` (parent cancellation), `join_timeout`, `startup_failed`, `startup_abandoned` (declined at the confirmation prompt) or `unknown`. While it is `reconnecting`, `tunnelReason` says why (`network`, `relay_error`, `agent_unavailable`, `agent_refused`, `auth_refused`, `relay_key_changed`, `relay_unsupported` or `proof_refused`), with `tunnelLostAt`, `tunnelError` and `nextAttemptAt`; a `disconnected` session's `tunnelReason` is `reconnect_unsupported`. `reconnect` is `supported` or `unsupported` once the first connection has shown which. `upterm session wait NAME` returns the command's exit code, 0 for explicit stop or join timeout, 128 plus the originating signal number for host or command signals, and 125 for cancellation or unavailable outcomes. Lookup, read and replacement failures, and cancellation of the waiter's context, return 125 with a diagnostic; interrupting the observer leaves the session alive. Legacy stopped records remain successful; legacy signal records without a valid numeric signal return 125. The on-disk record calls the numeric field `signal_number`. To keep a session open while a build runs and give people a window to join only if it fails, set the join timeout when the build is done instead of at launch. The script keeps the build's exit status, and works under `set -e`: ```sh upterm host --detach --accept --name build -- bash build_exit_code=0 make || build_exit_code=$? if [ "$build_exit_code" -ne 0 ]; then # Ten minutes for someone to join; once they have, it runs until they exit. if upterm session set build --join-timeout 10m; then upterm session wait build || true fi fi upterm session stop build || true # ends it either way; never masks the build's result exit "$build_exit_code" ``` The variable is `build_exit_code` rather than `status`, which zsh reserves. Interrupting `upterm session wait` on its own leaves the session running; in this script it falls through to `session stop`, which ends it. Each `session set` restarts the window from now, so running it again with the same duration extends the deadline; `--join-timeout 0` turns it off. A guest who joins at any point, even briefly or only over SFTP, claims the session: the join timeout is off for the rest of its life, and a later `session set` says so. `session info` shows the timeout and its deadline (`joinTimeout`, `joinDeadline` in the JSON), and where they came from (`joinStateSource`: the daemon, or the record when the session did not answer). `session info`, `session stop` and `session set` exit 4 when no session has the name. The hosted command sees its own name in `UPTERM_SESSION_NAME`. `upterm session list` shows every live session, including one started under a different `XDG_RUNTIME_DIR` — a cron job or a system service — reached through the admin socket path its record carries. Records outlive the sessions that wrote them for seven days, and the listing prunes the ones past that. Put a terminal on a session started without one, from any shell on the same machine: ```console upterm attach build-shell ``` Type `~.` at the start of a line to detach; the session keeps running, and `upterm attach` again picks up where the screen left off. On Unix, `~^Z` suspends the terminal instead — `fg` resumes it. `--escape-char none` sends every keystroke to the session. A session's own terminal counts as a client too: `session info` lists it as `host`, guests as `guest`, and a guest connection's forwards (see [Local TCP Forwarding](#local-tcp-forwarding)) as `jump`. In its JSON, `guestCount` counts currently connected guests (including jumps, excluding host terminals); scripts asking whether a terminal or SFTP guest has ever joined should use `firstGuestJoinedAt`. ### Reconnecting If the host's connection to the server drops — a Wi-Fi switch, a laptop waking up, a server deploy — `upterm host` reconnects on its own and keeps the same session ID, so the same connect string works again once it's back. While it retries, `upterm session info` shows `reconnecting`, why, and when it tries next. Nothing on the host stops: the command, its terminal and a local `upterm attach` carry on. The ID lasts as long as the `upterm host` process, not across a restart. (On a self-hosted relay with several nodes and no Consul, a host that comes back on another node gets a new connect string; `upterm session info` shows it.) Guests connected at the drop are disconnected. A guest who joined with `upterm join` rejoins on its own once the host is back, and says it's waiting and when it tries next until then. If the connect string changed, as in the note above, it keeps waiting on the old one and, after 5 minutes, adds that the session may have ended or moved: stop it with Ctrl-C and join the new one. A plain `ssh` guest rejoins with the same command; one who tries during the gap is told: ```text upterm: no host is connected for session ID right now. If it's reconnecting, try again once it's back; on some relays the host then has a new command to share. Otherwise it may have ended, or the ID may be wrong. ``` (A plain `ssh` guest who enters at another node of a multi-node relay reads a shorter form, in ssh's `channel 0: open failed` line: `…right now; it may have ended, or the ID may be wrong.`) For machines without upterm, this script rejoins an interactive session automatically and leaves the terminal usable after a drop. Save it as `upterm-rejoin` and run it in place of `ssh`, with the same arguments: ```bash #!/usr/bin/env bash # upterm-rejoin: rejoin an interactive upterm session when the connection drops. # Retries only when ssh itself fails (exit 255). Any other exit status is the # remote side ending — your shell's own `exit 1` included — and stops. It stops # too after 10 tries in a row that fail within 5 s, before the session starts. reset_modes() { printf '\030\0337\033[?1049l\033[?1047l\033[?47l\033[r\0338\033[?1l\033[?7h\033[?25h\033[?1000l\033[?1002l\033[?1003l\033[?1004l\033[?1005l\033[?1006l\033[?2004l\033[<u\033[>4m\033(B'; } trap reset_modes EXIT # also runs on Ctrl-C fails=0 while :; do start=$SECONDS ssh -t "$@"; rc=$? reset_modes [ "$rc" -eq 255 ] || exit "$rc" if [ $((SECONDS - start)) -lt 5 ]; then fails=$((fails + 1)); else fails=0; fi if [ "$fails" -ge 10 ]; then echo "upterm-rejoin: 10 tries in a row failed within 5 s; stopping. upterm join says why, and waits for a host that's reconnecting." >&2 exit 255 fi echo "upterm-rejoin: connection lost; rejoining in 3 s (Ctrl-C to stop)" >&2 sleep 3 || exit 130 done ``` - To stop, press Ctrl-C during the pause. While connected, Ctrl-C goes to the session. - ssh's `~.` also exits 255, and so reconnects; follow it with Ctrl-C. - A remote command that exits 255 is retried too, which is why the script is for interactive sessions only. - A refused key, a session that has ended and a host that's still away all exit 255 before the session starts, so after about half a minute of those the script stops. [`upterm join`](#joining-with-upterm-join) tells them apart, and keeps waiting for a host that's reconnecting. Reconnecting needs a server that supports it: uptermd 0.34.0 or later, which uptermd.upterm.dev runs. With an older one, `upterm session info` says `Reconnect: unsupported by this relay`, and a lost connection leaves the session `disconnected`, as before. ### Reach your own machine Leave a door open on a machine, at home say, and reach it from a laptop or a phone with plain `ssh`, `scp` and VS Code, through the relay, without opening a port. Only your own keys get in: 1. On the machine, pin the relay's key first, so the door checks the relay rather than trusting whatever answers: the lines are under [Running Without a Terminal](#running-without-a-terminal). 2. Open the door: ```console upterm host --detach --name home --full-access \ --authorized-user github:YOUR_GITHUB_USER \ --login-command herdr ``` - `--authorized-user github:YOUR_GITHUB_USER` lets in only the keys on your GitHub account, as they are when the door starts. - `--full-access` lets those keys do what an SSH login to your account can, without asking you: run commands, transfer files, and forward ports to this machine's loopback addresses. - `--login-command herdr` is what plain `ssh home` opens: a [Herdr][herdr-guide] client of its own for each guest. Without it, plain `ssh home` shares the door's own terminal. - `--detach` asks before it starts the door, on this terminal, then leaves it running in the background. 3. The door prints its ssh config as it starts. Print it again whenever you need it: ```console upterm session ssh-config home ``` Put both parts on each laptop: the `Host home` block in its `~/.ssh/config`, and the relay's line in its `~/.ssh/known_hosts`, once. The block's `User` changes whenever the door restarts, and on a relay that routes by node, also when the door comes back on another node, so print it again then. 4. From the laptop: `ssh home`, `scp notes.txt home:`, `sftp home`, or VS Code's **Remote-SSH: Connect to Host…** → `home`. The key `ssh home` offers has to be on your GitHub account, as it was when
Frequently Asked Questions
What is upterm?
upterm is a Utilities library for the Go programming language. A tool for developers to share terminal/tmux sessions securely over the web. It’s perfect for remote pair programming, accessing computers behind NATs/firewalls, remote debugging, and more
How many GitHub stars does upterm have?
upterm has 1,356 GitHub stars in the directory's latest synchronization.
How do I install upterm?
Install upterm with the Go module system using `go get owenthereal/upterm`. Check the repository for the current installation instructions.
What category does upterm belong to?
upterm is listed under Utilities, specifically Utilities.