Skip to main content

tunhub

Open the web UIs on your private network like any public website. tunhub sets up the SSH forwarding for you.

CI Python Platforms License: GPL v3+

Opening AdGuard from a browser favourite: tunhub starts the SSH tunnel by itself (the tile turns from grey to amber to purple) and the AdGuard page opens
A plain browser favourite opens AdGuard; tunhub starts the SSH tunnel on the way.

You self-host services with a web UI: Jupyter on a lab workstation, the admin page of your NAS, AdGuard, Grafana, ... For security, they stay off the public internet. So every time you need one, you first start an ssh -L forward, then recall which local port it was, then type the address. Again and again, on every computer you use.

tunhub takes those steps away. It runs quietly on your own computer: click a tile on its dashboard, or simply open a bookmark, and tunhub picks a route, opens the SSH tunnel if one is needed, waits until the service answers, and takes you there. When you are on the same LAN, it skips SSH and connects directly.

  • One click from the hub. Click a tile and the service opens in a new tab, with the tunnel already up.
  • Bookmarks that just work. Save http://hub.localhost:8765/open/nas in your favourites bar and use it like any public website. If the tunnel is down, tunhub opens it on the way; you never think about it.
  • Direct when it can, SSH when it must. On the same LAN, tunhub connects directly (cyan dot). Everywhere else, it goes through SSH (purple dot).
  • Addresses that never change. The NAS is always http://nas.localhost:15000, whatever the route, so saved passwords and cookies keep working.
  • Not just web pages. RDP, VNC, databases and other TCP services get an on/off tile that copies their address for your client.
  • Lightweight. One Python process using about 50 MB of memory and practically no CPU when idle, plus about 4 MB for each active ssh tunnel.

The tunhub dashboard: one tile per service, with a status dot showing whether it is connected directly or through SSH

Get started

You need an OpenSSH client (built into Linux, macOS and Windows 10+) and Python 3.10+. Install tunhub with any of:

uv tool install tunhub          # uv: its own environment; fetches Python if needed
pipx install tunhub             # pipx: its own environment
pip install tunhub              # pip: inside a virtual or conda environment

With pip, use a virtual or conda environment (many Linux distributions and Homebrew refuse a system-wide pip install), and keep that environment: tunhub service install starts tunhub with its Python. If the tunhub command is not on your PATH, python -m tunhub does the same.

Then:

tunhub init                     # writes a commented example config
$EDITOR ~/.config/tunhub/services.yaml
tunhub                          # then open http://hub.localhost:8765
tunhub service install          # optional: start automatically at login

Started without a config, the dashboard shows where the file goes and how to add your first service.

In Chromium-based browsers (Chrome, Edge, Brave) you can also install the dashboard as an app from the address bar. It then opens in its own window with its own dock or taskbar icon.

A service is a local port plus a list of routes, tried in order:

services:
  nas:
    local_port: 15000
    routes:
      - direct: 192.168.1.10:5000   # tried first, when you are at home
      - ssh: nas                    # Host alias from ~/.ssh/config
        remote: 127.0.0.1:5000      # as seen from the SSH server

SSH routes run non-interactively, so they need key authentication (or a loaded ssh-agent) and a host that is already in known_hosts. Run ssh <alias> once by hand for each host before you add it.

How it works

flowchart LR
    B["Browser<br/>nas.localhost:15000"] --> P["127.0.0.1:15000<br/>(tunhub)"]
    P -- "on the LAN: direct" --> N["NAS<br/>192.168.1.10:5000"]
    P -- "elsewhere: ssh -L" --> S["SSH host"] --> N

Whichever route wins, the service is served at the same local address:

route what listens on 127.0.0.1:15000
direct a TCP relay inside tunhub (like socat)
ssh ssh -N -L 127.0.0.1:15000:127.0.0.1:5000 nas

Each web service gets its own host name, http://<id>.localhost:<local_port>. Browsers share cookies between ports, but not between host names, so this keeps logins and password-manager entries apart. Chromium-based browsers and Firefox resolve *.localhost to 127.0.0.1 without any DNS setup.

Address or bookmark?

Every web service has two URLs, both shown in its ⋯ panel:

example what it is for
Bookmark http://hub.localhost:8765/open/nas Save this one in your browser. Opening it connects the service first (starting ssh if needed), then forwards you to the address.
Address http://nas.localhost:15000 Where the service itself lives. Your password manager and cookies are tied to it, and it never changes with the route. It only loads while the service is connected.

So you bookmark the hub link, and your password manager remembers the login under the address, without any extra setup.

Connection behaviour

A service is either in auto (the default) or on:

  • Auto: every 15 s, tunhub probes the direct routes of idle services and brings a service up as soon as one is reachable (cyan, "Direct"). This only opens the local port; nothing is kept open to the target until you use it. Auto never starts ssh: when the direct route is lost, the service simply goes back to off.
  • On: opening a service that is not up (tile click, bookmark, Start, autostart: true) tries the routes in order, including ssh. If it comes up on a direct route, it is simply in auto; if it needs ssh (purple, "SSH"), it stays on: tunhub keeps it up, and if ssh dies it tries all routes again from the first, backing off from 2 s to 60 s while every route fails. A working ssh connection is kept even if a direct route becomes reachable, so live sessions are not cut; when it drops (e.g. the laptop changed networks), the reconnect prefers the direct route and the service is back in auto. Opening a service that is already up just opens it, so a laptop that leaves home does not start ssh tunnels it no longer needs.
  • Stop (shown only for a service that is on) ends the connection and returns the service to auto; at home it is back on the direct route within a second. A service with auto_direct: false has no auto mode, so any connection to it is on until you stop it. There is no "stay off": set auto_direct: false for a service that should never connect by itself. Disconnect SSH in the top bar does the same for every service that uses or is trying ssh.
  • After a network change, ssh notices its dead connection within about 45 s (keep-alive). To switch immediately, click Stop and then the tile.

The ⋯ button on a tile shows its address, bookmark URL, route choice and live log:

Service details: address, bookmark URL, route selector and the active route

Configuration

tunhub init creates the config directory with a commented example:

OS config directory
Linux $XDG_CONFIG_HOME/tunhub or ~/.config/tunhub
macOS ~/.config/tunhub
Windows %APPDATA%\tunhub

To use another directory, set TUNHUB_CONFIG_DIR or pass --config-dir.

  • services.yaml is the shared definition. Keep it in a dotfiles repo to sync it between your machines.
  • local.yaml holds optional per-machine overrides and is merged on top of services.yaml: mappings key by key, lists such as routes as a whole. Use it when a machine is one of the servers (reach its services via 127.0.0.1, hide its own remote desktop with enabled: false), or when a port is taken. See local.example.yaml.

Click Reload config in the dashboard after editing. Services whose definition did not change keep their connections. Changes to the hub: section need a restart.

Every key is explained in the comments of the example files that tunhub init writes: services.yaml and local.example.yaml.

Start at login

tunhub service install     # also: uninstall, status
OS mechanism logs
Linux systemd user unit tunhub.service journalctl --user -u tunhub -f
macOS LaunchAgent ~/Library/Logs/tunhub.log
Windows Task Scheduler (pythonw, no console window) %LOCALAPPDATA%\tunhub\tunhub.log

The service runs the same Python interpreter that installed it. If you pass --config-dir (or have TUNHUB_CONFIG_DIR set), it is written into the service. On Linux, the systemd user session must see your ssh-agent (SSH_AUTH_SOCK); GNOME's agent normally takes care of that.

On Windows, stop tunhub before upgrading it, because Windows cannot replace a program that is running (uv then fails with "Access is denied"):

Stop-ScheduledTask -TaskName TunHub
uv tool upgrade tunhub
Start-ScheduledTask -TaskName TunHub

Security

  • The dashboard and all forwards listen on 127.0.0.1 only.
  • Requests whose Host is not the dashboard's own host name are rejected, which blocks DNS rebinding.
  • State-changing API calls need a custom header and a same-origin Origin, so other web pages cannot trigger them.
  • Other web pages cannot open a tunnel through /open/<id> either (for example with a hidden <img>): tunhub only accepts bookmarks, typed URLs, the dashboard itself and links that you click.
  • The dashboard refuses to be shown inside another site's frame (clickjacking).
  • Only services defined in your config can be opened. The web UI never runs arbitrary commands.
  • Service icons are fetched only through the service's own local port; tunhub never contacts other sites. They are served with a sandboxing CSP and shown only as <img>.

Direct routes on other networks: known_macs

Private addresses are reused everywhere. In a café whose network also uses 192.168.1.x, another device might answer on your NAS's address, and the browser would send it your NAS cookies. tunhub avoids such accidental misconnections the way ssh handles host keys with known_hosts:

  • The first time a direct route connects, tunhub records the MAC address of the next hop toward the target (the target itself on the same subnet, else the router) in known_macs, next to services.yaml: Permanently added 192.168.1.10 (aa:bb:cc:dd:ee:01) to known_macs.
  • Later, a direct route is used only if that MAC matches. Otherwise it is skipped (falling back to ssh, if configured) and the tile shows ⚠.
  • When the network changes, or cannot be determined, running direct routes are checked again; a route that still reaches the same machine stays up.
  • If a MAC changes for a good reason (new network card, another router), run tunhub forget <ip> or edit known_macs; several lines for one IP are all trusted. The file can be synced together with your config.

This prevents accidents, not deliberate attacks: someone on the same network can fake a MAC. Targets reached through a VPN have no visible MAC and are used without this check. Give direct targets a fixed address (a static IP or a DHCP reservation): a running direct route is re-checked when the network changes, not when an address is handed to another machine on the same network.

How does it compare?

opens on click picks direct or SSH nothing on servers non-web services
tunhub ✅ ✅ ✅ ✅
SSH tunnel managers (GUI / web) – – ✅ ✅
Homelab dashboards (Homer, Homepage, Dashy) ✅ – ✅ –
Mesh VPNs (Tailscale, ZeroTier, WireGuard) – ✅ – ✅
  • SSH tunnel managers handle individual -L forwards. You still map ports to services in your head, and nothing connects when you open a bookmark.
  • Homelab dashboards are link pages: they can't reach a service that needs a tunnel.
  • Mesh VPNs are great when you can install an agent on every server. tunhub is for the places where you can't or don't want to: university or company machines reachable only over SSH, jump hosts, or a NAS you would rather not run a VPN on.

Development

git clone https://github.com/LiukDiihMieu/tunhub && cd tunhub
uv sync --extra dev
uv run pytest
uv run tunhub --config-dir ./my-test-config

The tests use tests/fake_ssh.py in place of ssh to exercise the SSH routes, including reconnecting after the ssh process is killed.

Icons, logos and the social preview image are generated by tools/make_icons.py; see its docstring to regenerate them.

License

GPL-3.0-or-later. You may use, modify and redistribute tunhub, but any distributed modified version or derivative work must also be released under the GPL.

Metadata

Release files for tunhub 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tunhub 0.1.0
File Size Uploaded Provenance Actions
tunhub-0.1.0.tar.gz 160.4 kB With provenance Details for tunhub-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tunhub 0.1.0
File Interpreter ABI Platform Actions
tunhub-0.1.0-py3-none-any.whl Python 3 none any Details for tunhub-0.1.0-py3-none-any.whl

Total release size: 307.8 kB

Release files / tunhub-0.1.0.tar.gz

Download URL tunhub-0.1.0.tar.gz
Size 160.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f1e09b9835b5d6816868e03ad61c722b8510a04e22e770348bd36451e8f5ba23
BLAKE2b-256 checksum
How to use checksums
f86d3db71d68f6552ec1b89f8f559810b63fae6325fd04a564da8b982a581079
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / tunhub-0.1.0-py3-none-any.whl

Download URL tunhub-0.1.0-py3-none-any.whl
Size 147.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cceac0e77e844d0612f8217bacf2d8da35693f26a1b7496ac7741f48d56573b0
BLAKE2b-256 checksum
How to use checksums
1b6254d4bf97410441d83fb0f8f05eba786657db7f4ad88b39f89db2ebb2ce53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for tunhub 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tunhub-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page