How to Install RustDesk Server on a VPS with Docker: Your Own ID and Relay Server
Anyone who regularly gets asked for computer help knows the scene: a call from a parent or a colleague, something wrong on their screen, and you trying to guide them over the phone while guessing which button they are looking at. A remote desktop app settles that in minutes — you see their screen, move their cursor, and the problem is gone without a long round of verbal directions. The catch is that free remote desktop services usually limit devices, show ads, or change their terms whenever they please. And every session runs through the provider's servers.
RustDesk changes that arrangement. The app is free and open source, and you can run the server side yourself on a VPS. This guide installs RustDesk Server OSS on a VPS with Docker Compose: two small services, hbbs as the ID server and hbbr as the relay, plus a cryptographic key that makes clients trust only your server. When you are done, your devices register with your own server, and sessions that cannot connect directly fall back to your own relay instead of a public one.
Prerequisites
- A Linux VPS with Docker and Docker Compose v2 installed. The
network_mode: "host"setting in this guide only works on Linux. - One domain or public IP for the VPS that all clients can reach, for example
remote.example.com. The examples here use that domain; replace it with yours. - SSH access to the VPS with
sudorights. - The RustDesk client on both the controlled computer and the controlling computer, downloaded from the official RustDesk site.
Check Docker and Compose on the VPS first:
docker --version
docker compose versionExpected output: both commands print a version number with no error.
Step 1: create the folder and the Compose file
Create a working folder at /opt/rustdesk-server and move into it:
sudo mkdir -p /opt/rustdesk-server/data
cd /opt/rustdesk-serverOpen an editor and create compose.yml in that folder:
sudo nano compose.ymlFill it with the following, replacing remote.example.com with your VPS domain or public IP:
services:
hbbs:
container_name: hbbs
image: rustdesk/rustdesk-server:latest
command: hbbs -r remote.example.com:21117 -k _
volumes:
- ./data:/root
network_mode: "host"
depends_on:
- hbbr
restart: unless-stopped
hbbr:
container_name: hbbr
image: rustdesk/rustdesk-server:latest
command: hbbr -k _
volumes:
- ./data:/root
network_mode: "host"
restart: unless-stoppedWhat each part does:
hbbs is the ID server (rendezvous server). Clients register here, and when one client wants to reach another, hbbs introduces them.
hbbr is the relay server. It only carries session traffic when two devices cannot connect directly, for instance when both sit behind strict NAT.
-r remote.example.com:21117 tells hbbs which relay address to hand out to clients.
-k _ turns on the shared key: clients without the matching key cannot use this server.
./data:/root keeps the server keys and the peer database in the data folder, so they survive container recreation.
network_mode: "host" puts the containers directly on the host network. That matters because hbbs needs to see the client's real IP, not Docker's internal address.
Save the file (Ctrl+O, Enter, Ctrl+X in nano).
Step 2: open the firewall ports
RustDesk OSS uses the following ports, according to its official documentation:
| Port | Protocol | Service | Purpose |
|---|---|---|---|
| 21115 | TCP | hbbs | NAT type test |
| 21116 | TCP and UDP | hbbs | ID registration and heartbeat |
| 21117 | TCP | hbbr | Relay |
| 21118 | TCP | hbbs | Web client (optional) |
| 21119 | TCP | hbbr | Web client (optional) |
Port 21116 must be open for TCP and UDP; UDP carries ID registration and heartbeat traffic. Ports 21118 and 21119 are only needed if you use the web client — otherwise, leave them closed.
With UFW, the commands are:
sudo ufw allow 21115/tcp
sudo ufw allow 21116/tcp
sudo ufw allow 21116/udp
sudo ufw allow 21117/tcp
sudo ufw reloadExpected output: each command answers Rule added (or Rule updated), and sudo ufw status lists all four rules.
Step 3: start the server and collect its public key
From /opt/rustdesk-server, start the stack:
sudo docker compose up -dThen check the hbbs log:
sudo docker compose logs --tail=50 hbbsExpected output: log lines showing hbbs listening on port 21116 and a base64 Key: value. On its first run, hbbs generates an Ed25519 key pair and stores it in the data folder. You can also read the public key straight from the file:
sudo cat /opt/rustdesk-server/data/id_ed25519.pubExpected output: one long line of base64 characters ending in =. Keep this value — you will paste it into every client. Guard its partner file, id_ed25519 (the private key): keep it on the server and never share it. If the private key leaks, or is lost and regenerated, every client must be reconfigured with the new public key.
Confirm both containers are running:
sudo docker compose psExpected output: hbbs and hbbr both show as running (or Up).
Step 4: point each client at your server
Repeat this on every device: the controlled machine and the controlling machine.
- Open the RustDesk app.
- Click the menu button (three dots) next to your ID, then open Settings.
- Go to the Network tab and click Unlock Network Settings.
- Fill in the following: ID Server: remote.example.com (your VPS domain or IP); Relay Server: remote.example.com; Key: paste the contents of id_ed25519.pub from step 3; API Server: leave it empty — that field is only for RustDesk Server Pro.
- Close Settings.
The sign of success is in the main window: the initial message "Ready, For faster connection, please set up your own server" shortens to just "Ready". That means the client is registered with your server rather than the public one. The device's own ID does not change, so you still connect to it with the same ID as before.
Step 5: test a connection through your own server
From the controlling computer, enter the target device's ID in the "Enter Remote ID" box, connect, and enter the target's password. Once that works, verify one more thing: whether sessions genuinely pass through your relay when a direct connection fails. The honest way is to watch the relay log during a session:
sudo docker compose logs --tail=100 hbbrIf the devices are on different networks behind strict NAT, the hbbr log will show relay activity during the session. If both devices share one local network, the session may connect directly without the relay — that is normal, and faster too.
If you want to force all traffic through the relay (for example, for auditing on an office network), add the environment variable ALWAYS_USE_RELAY=Y to the hbbs service in compose.yml and restart with sudo docker compose up -d. For personal use, leave that off so direct sessions remain possible.
Troubleshooting
The client still shows the public-server message. The network settings were not saved, or the client was not fully restarted. Quit RustDesk completely (including the system tray icon), reopen it, and recheck the ID Server, Relay Server, and Key fields. A single wrong character in the public key is enough for the client to reject the server.
The client fails to connect at all. Check three things in order: (1) the containers are running (sudo docker compose ps), (2) the ports are reachable from outside — test from another machine with nc -vz remote.example.com 21116, (3) your cloud provider's firewall (security group) opens the same ports, since UFW alone is not enough when a cloud-level firewall sits in front.
ID registration fails even though the TCP port looks open. This is the classic symptom of a closed 21116/UDP. Registration and heartbeat use UDP, and many people only open TCP. Add the 21116/udp rule from step 2.
Sessions connect but drop frequently. Check both services' logs (sudo docker compose logs --tail=100 hbbs hbbr) and the VPS load. A relay short on bandwidth or CPU drops relayed sessions while direct sessions stay fine — that pattern points the diagnosis at hbbr, not at the client.
The public key changed after recreating the containers. That happens when the data folder is not actually mounted, for instance because Compose was run from a different directory. Always run docker compose from /opt/rustdesk-server, and confirm data/id_ed25519.pub still exists before restarting.
Summary table
| Component | Role | Ports | File / note |
|---|---|---|---|
| hbbs | ID server, introduces clients | 21115 TCP, 21116 TCP/UDP | Keys in data/id_ed25519.pub |
| hbbr | Relay when direct connection fails | 21117 TCP | Shares the data volume with hbbs |
| Client | Registers with your own server | — | ID Server + Relay Server + Key under Settings → Network |
| Firewall | Opens the path from clients to the server | 21115–21117 | 21118/21119 only for the web client |
Final checklist
- The hbbs and hbbr containers are running.
- Ports 21115 TCP, 21116 TCP and UDP, and 21117 TCP are open in both the VPS firewall and the cloud provider's firewall.
- The public key from data/id_ed25519.pub is recorded and pasted into every client.
- The "set up your own server" message is gone from the client window, replaced by "Ready".
- One remote session connected successfully through your own ID server.
- The /opt/rustdesk-server/data folder is covered by your backup plan, because the private key inside it cannot be recreated without reconfiguring every client.
One maintenance habit: from /opt/rustdesk-server, run sudo docker compose pull && sudo docker compose up -d regularly to pick up new image releases, then check the logs afterwards. The keys in the data folder do not change as long as that volume stays mounted.
Have you ever moved from a paid remote desktop service to your own server? What held you back the most — the firewall, the keys, or configuring every device? Tell us in the comments, and if any step above fails on your VPS, post the error message so it can be worked through together.
Read also: the Rnevio article "WireGuard: Bangun VPN Pribadi di VPS" explains how to secure your server administration path with a personal VPN, while the paired guide in this batch is available at a Meilisearch guide to self-hosted search on a VPS.


Diskusi
Ada pertanyaan atau pengalaman yang ingin dibagikan?
Komentar ditinjau sebelum ditampilkan. Mari berdiskusi dengan sopan dan sesuai topik.
Tulis komentar