
RustDesk is an open-source remote desktop solution that gives you full control of your remote connections through a self-hosted server. It is an alternative to closed-source applications such as TeamViewer and AnyDesk, with a lightweight interface and end-to-end encrypted sessions that route through infrastructure you own.
This article explains how to install the RustDesk server on Ubuntu using Docker Compose. It covers deploying the ID and relay services, opening the ports that RustDesk clients require, retrieving the server encryption key, and connecting a client to your own server.
Before you begin, you need to:
rustdesk.example.com to your server's public IP address.The RustDesk server runs as two services. hbbs is the ID and rendezvous server that registers clients and brokers connections between them. hbbr is the relay server that carries session traffic when two clients cannot reach each other directly.
Both services use their own binary protocols rather than HTTP, so they cannot be placed behind a standard HTTP reverse proxy. Clients connect to the ports directly, which means the firewall must permit them.
Docker Compose runs both services from a single file and restarts them automatically after a reboot. The compose file also maps a local directory into the containers so that the generated encryption key and the ID database survive container replacement.
Create a directory to hold the RustDesk files.
Change to the directory.
Create the compose file.
Add the following configuration. Replace rustdesk.example.com with your subdomain or your server's public IP address.
Save and close the file.
command: hbbs -r rustdesk.example.com:21117: Tells the ID server which relay address to hand out to clients. This value must be an address that clients can reach, so a loopback address such as 127.0.0.1 prevents relayed sessions from working.volumes: ./data:/root: Persists the generated key pair and the ID database in /opt/rustdesk/data so that clients keep working after the containers are recreated.restart: unless-stopped: Restarts both services automatically after a reboot.Verify that the compose file parses correctly.
The output displays the resolved configuration. A YAML error here means the indentation does not match the file above.
Start the services.
Verify that both containers are running.
The output displays the hbbs and hbbr containers with an Up status and their mapped ports.
RustDesk clients connect to the server ports directly, so each one must be permitted through the firewall. Missing the UDP mapping on port 21116 is a common cause of clients that never come online, because that port carries the registration heartbeat.
Allow SSH so that enabling the firewall does not end your session.
Allow the ID server ports.
Allow the registration port over both protocols.
Allow the relay port.
Allow the web client ports.
Enable the firewall.
The command warns that it may disrupt existing SSH connections and asks for confirmation. Enter y to proceed.
Review the active rules.
The output displays OpenSSH and each RustDesk port with an ALLOW action.
The ID server generates an Ed25519 key pair on first start and stores it in the mounted data directory. Clients must present the matching public key to register, which prevents unknown clients from using your server.
Display the public key.
The output displays a single base64 string that ends with an equals sign.
Copy the value. Every client that connects to this server needs it.
Keep the private key in /opt/rustdesk/data/id_ed25519 on the server. Deleting the data directory regenerates the key pair, and every client must then be reconfigured with the new public key.
Each client stores the server address and public key in its network settings. Repeat these steps on every machine you want to reach, including the machine you connect from.
Download the RustDesk client for your operating system from the official website.
Install and open the application.
Click the menu button next to your connection ID, then select Settings.
Select Network, then unlock the ID/Relay Server section.
Enter your subdomain or server IP address in the ID Server field.
Paste the server public key into the Key field.
Click OK to save the settings.
The connection indicator turns green once the client registers with your server.
Note the ID and one-time password shown on the machine you want to control. To set a permanent password instead, open Settings, then Security, and set an unattended access password.
Confirming a session end to end proves that both the ID server and the relay are reachable, and that the key matches on both sides.
Configure a second machine with the same ID Server and Key values.
Enter the remote machine's ID in the Control Remote Desktop field.
Click Connect.
Enter the remote machine's password when prompted.
The remote desktop appears. Traffic now routes through your own server rather than the public RustDesk infrastructure.
You have installed a self-hosted RustDesk server on Ubuntu with Docker Compose, opened the ports that clients require, and connected a client using the server's encryption key. Because both services speak their own protocols rather than HTTP, keep the ports reachable rather than placing the server behind an HTTP reverse proxy. For more information, visit the official RustDesk documentation.
0 Comments
Be the first to comment and share your perspective with the community.