---
title: Self-hosting on Linux
description: Running your own Bridge on a Linux machine with install.sh --server. The four services, their ports and state, the first invite, upgrades and removal.
section: Linux
order: 40
---

A Linux machine can host a Bridge, not just join one. The same installer does
it:

```bash
curl -fsSL https://bridgedesktop.com/install.sh | sh -s -- --server --owner dan
```

When it finishes, the machine is running a complete Bridge, is joined to it as
a workspace, and prints a green box with an invite key. Paste that key into
Bridge on your laptop (or into the Linux one-liner on another machine) to join.

Source: `crates/agent/src/host.rs` (`bridgectl server`),
`packages/agent/scripts/build-linux-server.sh` (what is in the download), and
`site/public/install.sh`. It is the Linux counterpart of what the macOS and
Windows apps do by themselves on first launch, where every install sets up its
own Bridge with no questions (and of **Create a team** in their server list).

## Requirements

- Everything the [Linux install](/docs/linux-install/) needs.
- 64-bit Linux with glibc. The server is compiled with Bun, whose Linux builds
  link glibc: Debian, Ubuntu, Fedora and Raspberry Pi OS work; Alpine does not.
- About 300 MB of disk for the server component, plus your team's data.
- Outbound HTTPS. Nothing inbound: no port forwarding, no open firewall port.

## What `--server` does

1. Installs the base agent, exactly as a normal install does.
2. Downloads the `server` component (about 85 MB compressed) for the agent's
   exact version, and verifies its size, SHA-256 and release signature before
   unpacking it into `/usr/local/lib/bridge/server`. See
   [Components and updates](/docs/components-and-updates/).
3. Runs `bridgectl server setup --owner NAME`, which brings up four services
   (below), checks that the control plane's fingerprint matches the key it
   actually serves, and joins the machine to its own tailnet as the node
   `bridge`.
4. Mints the owner's first invite and joins this machine to its own Bridge
   with it, through the normal client path. The only difference from any other
   machine is that it reaches its control plane on loopback
   (`bridge-tailnet --relay-override http://127.0.0.1:2660`) rather than out
   through the internet relay and back.
5. That sign-in is the Bridge's first user, so `NAME` becomes the org owner.
6. Mints a second invite, for your laptop, and prints it.

## Services and ports

Everything listens on loopback only.

| unit | listens on | what it is |
| --- | --- | --- |
| `bridge-headscale` | `127.0.0.1:2660` | The tailnet's control plane (Headscale 0.29.7, built from headfwd's fork, which adds a configurable map keep-alive). Admits nodes, assigns addresses, enforces the ACL policy. |
| `bridge-sidecar` | `127.0.0.1:2661` | Mints invite keys, owns the ACL policy, and registers this control plane with the public relays so machines anywhere can reach it. |
| `bridge-server-tailscaled` | SOCKS5 `127.0.0.1:2662` | The server's own tailnet node, named `bridge` and tagged `tag:bridge-server`. Runs with `--no-logs-no-support`, so it sends no logs to Tailscale. |
| `bridge-server` | `127.0.0.1:2687` | Bridge itself: the web app, the API and the agent hub. |

Plus the three client units every Linux install has (`bridge-tailscaled`,
`bridge-tailnet`, `bridge-agent`), because this machine is also a workspace.

Clients reach the server over the tailnet at `http://bridge:2687`. The server
node's userspace `tailscaled` delivers those connections to `127.0.0.1:2687`,
and tells the server which tailnet user each one came from, which is how
sign-in works with no password.

## Files

| path | contents |
| --- | --- |
| `/usr/local/lib/bridge/server/` | `bridge-server`, `web/`, `headscale`, `tailnet-sidecar`, the ACL seed, licences. Replaced on update. |
| `/var/lib/bridge/host/` | The control plane: `config.yaml`, Headscale's database and private keys, the API key, the sidecar token, the enroll secret, the server node's tailnet state, and the two `EnvironmentFile`s. Secrets are mode 0600. |
| `/var/lib/bridge/server/` | Bridge's own data: the SQLite database with every project, chat and member, under `data/`. Hourly and daily snapshots go to `data/backups/` (`bridge-<kind>-<time>.sqlite.zst`, zstd; older ones `.sqlite.gz`), automatic CPU profiles to `data/profiles/`. |

Back up both `/var/lib/bridge/host` and `/var/lib/bridge/server`. Losing `host`
means losing the control plane's identity, and every machine would need a new
invite.

## Security properties

- **The ACL policy lives in Headscale's database** and is owned by the sidecar,
  which declares each invite's `tag:user-<name>` at the moment it is minted.
- **The enroll secret is random**, generated on first setup and stored 0600.
  It is checked only for an agent the Bridge tailnet cannot identify. A machine
  that joined the tailnet with an invite enrols on its tailnet identity alone,
  which is why a desktop app connects without ever being told the secret.
- **Secrets never go on a command line.** The Headscale API key and the sidecar
  token reach the sidecar through an `EnvironmentFile`, and preauth keys reach
  `tailscale up` through a 0600 file.
- **Invites are single-use and expire after 24 hours**, enforced by Headscale.

## More invites

```bash
sudo bridgectl server invite alice
```

Or from Bridge itself, under **Org → Users**, as on any Bridge.

## Status and logs

```bash
sudo bridgectl server status
sudo journalctl -u bridge-server -u bridge-headscale -u bridge-sidecar -f
```

Each request is one log line with its latency, response size and SQLite cost:

```text
14:02:11  200  /api/projects/abc  request completed  41ms  12.3kb  db 3.1ms/7q
```

For history (slowest routes, slow queries, event-loop stalls, CPU profiles),
read the server's own metrics on the box with
[`sudo bridgectl metrics`](/docs/bridgectl/#metrics).

## Upgrades

Self-update moves the server with the agent. When a new release arrives, the
daily timer verifies and installs the new server component, restarts
`bridge-server`, and then updates the agent, so the two never run different
releases. A server update that cannot be fetched or verified stops the update
before anything is replaced.

The first start after an upgrade can take longer than usual on a large
database. That happens when the release adds an index or summary table, which
is built once, before the server starts listening, and logged with its
duration (`[db] built ...`). Expect roughly one second per gigabyte of
database. Later starts skip it.

## Database memory

The server keeps a SQLite page cache of 1/32 of the machine's RAM, between 32
MB and 256 MB. Memory is used only as pages are read, so a small database never
fills it. To pin a size, set `SQLITE_CACHE_MB` in the server's environment, for
example `SQLITE_CACHE_MB=512`. The value is read once at startup.

## Removing it

```bash
sudo bridgectl uninstall
```

This stops and removes all seven units and the binaries, but **keeps**
`/var/lib/bridge/host` and `/var/lib/bridge/server`, because they are your
team's data. To delete those too:

```bash
sudo bridgectl uninstall --purge-server
```

## Moving part of a Bridge to another server

You can move some teams or projects to their own server while the rest stay.
For example, one Bridge shared by a company and a family can become two.

A source checkout includes an offline tool for this. It works from a snapshot
of the database. For each new server, it writes a bundle holding that team's
projects, chats, calls, files and hosted repos. You choose which credentials
and tailnet state the bundle starts without.

You install a bundle by placing it in a freshly set-up server's
`/var/lib/bridge/server/data/`. The procedure, including how to keep the
existing server's tailnet identity so its people don't re-enroll, is in
`docs/splitting-a-server.md` in the Bridge repository.

## Known limits

- **Server discovery picks port 5173 first.** If this machine also runs
  another Bridge on port 5173 (a development checkout, say), a client may find
  that one first.
- **Relays are a dependency for remote machines.** Machines on the same host
  reach the control plane on loopback; everything else reaches it through the
  public relays (`bridgeproxy.net`, `headfwd.net`), which see only sealed
  traffic. See [Networking](/docs/networking/).
