> ## Documentation Index
> Fetch the complete documentation index at: https://felimet-hub.jmcores.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-Hosted RustDesk Server

> Self-host a RustDesk remote desktop server with hbbs, hbbr, and the Web API console in one container, fronted by Cloudflare Tunnel with no device limit.

export const OptionPicker = ({options = [], lang = "zh", label}) => {
  const t = lang === "en" ? {
    pick: label || "Pick an option to compare",
    rec: "Recommended"
  } : {
    pick: label || "點選項目比較",
    rec: "推薦"
  };
  const opts = Array.isArray(options) ? options : [];
  const [sel, setSel] = useState(0);
  if (opts.length === 0) return null;
  const idx = Math.min(sel, opts.length - 1);
  const cur = opts[idx];
  const css = `
  .op-root{--op-bg:#FAF8F3;--op-surface:rgba(0,0,0,0.025);--op-border:rgba(0,0,0,0.09);--op-text:#2b2722;--op-dim:#6f6a62;--op-faint:#8a8378;--op-accent:#bf7551;border:1px solid var(--op-border);border-radius:14px;background:var(--op-bg);color:var(--op-text);overflow:hidden;}
  .dark .op-root{--op-bg:#1b1a18;--op-surface:rgba(255,255,255,0.03);--op-border:rgba(255,255,255,0.08);--op-text:#e7e3da;--op-dim:#a8a299;--op-faint:#8a8378;--op-accent:#cf8a68;}
  .op-head{padding:12px 16px 11px;border-bottom:1px solid var(--op-border);font-size:12.5px;color:var(--op-dim);display:flex;align-items:center;gap:8px;}
  .op-head-ic{color:var(--op-accent);flex-shrink:0;}
  .op-tabs{display:flex;gap:8px;padding:14px 16px 4px;flex-wrap:wrap;}
  .op-tab{position:relative;flex:1 1 130px;min-width:120px;text-align:left;background:transparent;border:1px solid var(--op-border);border-radius:11px;padding:11px 13px;cursor:pointer;color:inherit;font:inherit;transition:border-color .15s,background .15s,box-shadow .15s;}
  .op-tab:hover{background:var(--op-surface);}
  .op-tab-on{border-color:rgba(191,117,81,.5);background:rgba(191,117,81,.07);box-shadow:0 0 0 3px rgba(191,117,81,.1);}
  .op-tab-name{font-size:14.5px;font-weight:600;line-height:1.3;}
  .op-tab-on .op-tab-name{color:var(--op-accent);}
  .op-badge{display:inline-block;margin-top:6px;font-size:10.5px;font-weight:700;letter-spacing:.4px;text-transform:uppercase;padding:2px 7px;border-radius:20px;background:rgba(191,117,81,.14);color:var(--op-accent);}
  .op-rec{position:absolute;top:10px;right:11px;font-size:10px;font-weight:700;letter-spacing:.3px;text-transform:uppercase;color:var(--op-accent);}
  .op-body{padding:6px 16px 16px;}
  .op-specs{border:1px solid var(--op-border);border-radius:10px;overflow:hidden;margin-bottom:11px;}
  .op-row{display:flex;border-top:1px solid var(--op-border);font-size:13px;}
  .op-row:first-child{border-top:none;}
  .op-k{width:42%;flex-shrink:0;padding:8px 12px;color:var(--op-dim);background:var(--op-surface);}
  .op-v{flex:1 1 0;min-width:0;padding:8px 12px;font-weight:500;}
  .op-note{font-size:13px;line-height:1.6;color:var(--op-dim);padding:0 2px;}
  `;
  return <div className="op-root">
      <style>{css}</style>
      <div className="op-head"><svg className="op-head-ic" xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z" /><path d="m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65" /><path d="m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65" /></svg>{t.pick}</div>
      <div className="op-tabs">
        {opts.map((o, i) => <button key={i} type="button" className={"op-tab" + (i === idx ? " op-tab-on" : "")} onClick={() => setSel(i)}>
            {o.recommend && <span className="op-rec">★ {t.rec}</span>}
            <div className="op-tab-name">{o.name}</div>
            {o.badge && <span className="op-badge">{o.badge}</span>}
          </button>)}
      </div>
      <div className="op-body">
        <div className="op-specs">
          {(cur.specs || []).map((row, i) => <div className="op-row" key={i}>
              <div className="op-k">{row[0]}</div>
              <div className="op-v">{row[1]}</div>
            </div>)}
        </div>
        {cur.note && <div className="op-note">{cur.note}</div>}
      </div>
    </div>;
};

export const ArchFlow = ({nodes = [], lang = "zh"}) => {
  const t = lang === "en" ? {
    flow: "Data flow",
    hint: "Click any stage to see what it does",
    stage: "Stage"
  } : {
    flow: "資料流",
    hint: "點任一階段看它做什麼",
    stage: "階段"
  };
  const safe = Array.isArray(nodes) ? nodes : [];
  const [active, setActive] = useState(0);
  if (safe.length === 0) return null;
  const idx = Math.min(active, safe.length - 1);
  const current = safe[idx];
  const css = `
  .af-root{--af-bg:#FAF8F3;--af-surface:rgba(191,117,81,0.06);--af-surface2:rgba(0,0,0,0.025);--af-border:rgba(0,0,0,0.09);--af-text:#2b2722;--af-dim:#6f6a62;--af-faint:#8a8378;--af-rail:rgba(0,0,0,0.12);--af-accent:#bf7551;border:1px solid var(--af-border);border-radius:14px;background:var(--af-bg);color:var(--af-text);overflow:hidden;}
  .dark .af-root{--af-bg:#1b1a18;--af-surface:rgba(207,138,104,0.09);--af-surface2:rgba(255,255,255,0.03);--af-border:rgba(255,255,255,0.08);--af-text:#e7e3da;--af-dim:#a8a299;--af-faint:#8a8378;--af-rail:rgba(255,255,255,0.13);--af-accent:#cf8a68;}
  .af-head{padding:13px 18px 11px;display:flex;align-items:center;gap:9px;flex-wrap:wrap;border-bottom:1px solid var(--af-border);}
  .af-head-ic{color:var(--af-accent);flex-shrink:0;}
  .af-head-t{font-size:12px;font-weight:700;letter-spacing:.6px;color:var(--af-dim);text-transform:uppercase;}
  .af-head-h{font-size:12px;color:var(--af-faint);}
  .af-grid{display:flex;gap:0;align-items:stretch;}
  .af-list{flex:1 1 0;min-width:0;padding:12px 12px 16px;}
  .af-node{display:flex;align-items:stretch;gap:10px;width:100%;text-align:left;background:transparent;border:none;cursor:pointer;padding:0;color:inherit;font:inherit;-webkit-tap-highlight-color:transparent;}
  .af-railcol{width:22px;flex-shrink:0;display:flex;flex-direction:column;align-items:center;}
  .af-dot{width:9px;height:9px;border-radius:50%;margin-top:14px;background:var(--af-faint);opacity:.5;flex-shrink:0;transition:background .15s,box-shadow .15s,opacity .15s;}
  .af-line{width:2px;flex:1 1 0;background:var(--af-rail);min-height:10px;}
  .af-body{flex:1 1 0;min-width:0;padding:9px 12px;margin:2px 0;border-radius:9px;border:1px solid transparent;transition:background .15s,border-color .15s;}
  .af-node:hover .af-body{background:var(--af-surface2);}
  .af-node-on .af-body{background:var(--af-surface);border-color:rgba(191,117,81,.30);}
  .af-node-on .af-dot{background:var(--af-accent);opacity:1;box-shadow:0 0 0 4px rgba(191,117,81,.15);}
  .af-label{font-size:14.5px;font-weight:550;line-height:1.45;}
  .af-node-on .af-label{color:var(--af-accent);}
  .af-detail{width:300px;flex-shrink:0;border-left:1px solid var(--af-border);padding:16px 18px;background:var(--af-surface2);}
  .af-detail-k{font-size:11px;font-weight:700;letter-spacing:.5px;text-transform:uppercase;color:var(--af-accent);margin-bottom:7px;}
  .af-detail-l{font-size:16px;font-weight:600;margin-bottom:9px;line-height:1.35;}
  .af-detail-d{font-size:13.5px;line-height:1.65;color:var(--af-dim);}
  @media (max-width:640px){.af-grid{flex-direction:column;}.af-detail{width:auto;border-left:none;border-top:1px solid var(--af-border);}}
  `;
  return <div className="af-root">
      <style>{css}</style>
      <div className="af-head">
        <svg className="af-head-ic" xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect width="8" height="8" x="3" y="3" rx="2" /><path d="M7 11v4a2 2 0 0 0 2 2h4" /><rect width="8" height="8" x="13" y="13" rx="2" /></svg>
        <span className="af-head-t">{t.flow}</span>
        <span className="af-head-h">{t.hint}</span>
      </div>
      <div className="af-grid">
        <div className="af-list">
          {safe.map((n, i) => <button key={i} type="button" className={"af-node" + (i === idx ? " af-node-on" : "")} onClick={() => setActive(i)} onMouseEnter={() => setActive(i)}>
              <div className="af-railcol">
                <div className="af-dot" />
                {i < safe.length - 1 && <div className="af-line" />}
              </div>
              <div className="af-body">
                <div className="af-label">{n.label}</div>
              </div>
            </button>)}
        </div>
        <div className="af-detail">
          <div className="af-detail-k">{t.stage} {idx + 1} / {safe.length}</div>
          <div className="af-detail-l">{current.label}</div>
          <div className="af-detail-d">{current.detail}</div>
        </div>
      </div>
    </div>;
};

`RustDesk` · `Docker` · `Cloudflare Tunnel` · `Self-Hosted` · `Remote Desktop`

## Overview

This project builds a self-hosted remote desktop infrastructure using the community image `lejianwen/rustdesk-server-s6`. The image uses s6-overlay to bundle hbbs (signal server), hbbr (relay server), and a Go-based Web API management console into a single container. A second cloudflared container shares the same network namespace, exposing the Web console through a Cloudflare Zero Trust Tunnel. RustDesk clients connect directly to the host on ports 21115-21117. There is no device-count limit, and the image is MIT-licensed.

## Core features

* Single container bundles hbbs + hbbr + Web API (no three-container coordination needed)
* Web console exposed via Cloudflare Tunnel; no inbound port opened on the host for the console
* RustDesk clients connect directly on 21115-21117, bypassing the Tunnel for lowest latency
* User management, device management, address book/groups, login logs, connection logs, OIDC/LDAP login, Web Client, forced login (`MUST_LOGIN=Y`)
* No device-count limit, MIT licence

## Configuration options

<OptionPicker
  lang="en"
  options={[
{
name: "Official OSS",
specs: [["Image", "rustdesk/rustdesk-server"], ["Web console", "No"], ["Device limit", "None"], ["Forced login", "No"], ["OIDC / LDAP", "No"], ["Licence", "AGPL"], ["Support", "Community"]],
note: "Signal + relay only, no Web console. Fits a minimal hole-punching deployment you manage yourself."
},
{
name: "Community", badge: "this repo", recommend: true,
specs: [["Image", "lejianwen/rustdesk-server-s6"], ["Web console", "Yes"], ["Device limit", "None"], ["Forced login", "Yes (MUST_LOGIN=Y)"], ["OIDC / LDAP", "Yes"], ["Licence", "MIT (free)"], ["Support", "Community"]],
note: "Single container bundling hbbs + hbbr + Web API, no device limit, MIT and free. Used by this project."
},
{
name: "Official Pro",
specs: [["Image", "rustdesk/rustdesk-server-pro"], ["Web console", "Yes"], ["Device limit", "3 (free tier)"], ["Forced login", "Yes"], ["OIDC / LDAP", "Yes"], ["Licence", "Commercial"], ["Support", "Official"]],
note: "Officially maintained and full-featured, but the free tier is capped at 3 devices; more needs a commercial licence."
}
]}
/>

## Architecture

<ArchFlow
  lang="en"
  nodes={[
{ label: "Client / Admin browser", detail: "RustDesk clients connect directly to the host on TCP/UDP ports 21115-21117, bypassing the Tunnel for lowest latency. The admin browser reaches the Web console through Cloudflare Edge." },
{ label: "Cloudflare Edge", detail: "Entry point for admin traffic: handles TLS termination and WAF, then forwards the request into the Cloudflare Tunnel." },
{ label: "Cloudflare Tunnel", detail: "Outbound-only reverse tunnel. The cloudflared container dials out to Cloudflare, so no inbound port needs to be opened on the host for the Web console." },
{ label: "cloudflared container", detail: "Shares a network namespace with rustdesk-s6 via network_mode: service:rustdesk, reaching localhost:21114 directly without any additional exposed ports." },
{ label: "rustdesk-s6 container", detail: "s6-overlay runs hbbs (signal server), hbbr (relay server), and the Go Web API console together in a single container, with no device-count limit." }
]}
/>

The two containers (rustdesk-s6 and cloudflared) share a network namespace via `network_mode: service:rustdesk`, so cloudflared reaches `localhost:21114` directly without any additional exposed ports.

## Quick start

<Steps>
  <Step title="Clone the repo and configure environment variables">
    ```bash theme={null}
    git clone https://github.com/felimet/self-host-rustdesk-server
    cd self-host-rustdesk-server
    cp .env.example .env
    ```

    Two values are required in `.env`: `CLOUDFLARE_TUNNEL_TOKEN` (obtained when creating a Tunnel in the Cloudflare Zero Trust Dashboard) and `RUSTDESK_API_JWT_KEY` (any random string you choose).
  </Step>

  <Step title="Start services">
    ```bash theme={null}
    docker compose up -d
    ```
  </Step>

  <Step title="Retrieve the server public key">
    ```bash theme={null}
    cat ./data/server/id_ed25519.pub
    ```

    This key goes into the "Key" field of the RustDesk client configuration. It also appears in the container logs.
  </Step>

  <Step title="First login to the Web console">
    Open `https://rustdesk-console.example.com` (the hostname you configured in Cloudflare Tunnel). The default username is `admin`; get the initial password from the container logs:

    ```bash theme={null}
    docker logs rustdesk
    ```

    Change the password immediately after first login.
  </Step>

  <Step title="Configure the RustDesk client">
    | Field        | Value                                                   |
    | ------------ | ------------------------------------------------------- |
    | ID server    | `rustdesk-server.example.com` (direct hostname)         |
    | Relay server | Same as above, or leave blank                           |
    | API server   | `https://rustdesk-console.example.com` (full HTTPS URL) |
    | Key          | Public key from step 3                                  |

    The ID and relay server fields take only the hostname, without `http://` or a port number.
  </Step>
</Steps>

## Notes

<Warning>
  The `PROXY_ENABLE` and `TRUST_PROXY` parameters in `docker-compose.yml` and `.env` directly affect brute-force blocking and real attacker IP identification. Do not change these without understanding the security implications (see the architecture and maintenance guide in `docs/`). Keep `.env` out of version control: it contains the Tunnel token and JWT key. `data/server/id_ed25519` is the private key and must never leave the server; `id_ed25519.pub` is the public key distributed to clients.
</Warning>

## In practice

Lab members use this to access lab workstations remotely without relying on a commercial remote desktop service. Connection records stay on the self-managed server. The administrator manages user accounts and devices through the Web console, and `MUST_LOGIN=Y` ensures that unauthenticated clients cannot establish sessions.

## Links

* GitHub: [felimet/self-host-rustdesk-server](https://github.com/felimet/self-host-rustdesk-server)
* lejianwen/rustdesk-server (community server fork): [github.com/lejianwen/rustdesk-server](https://github.com/lejianwen/rustdesk-server)
* lejianwen/rustdesk-api (Web API backend): [github.com/lejianwen/rustdesk-api](https://github.com/lejianwen/rustdesk-api)
* RustDesk official OSS server: [github.com/rustdesk/rustdesk-server](https://github.com/rustdesk/rustdesk-server)
