How to Install and Configure RustDesk Server on Ubuntu: Build a Secure Self-Hosted TeamViewer Alternative

Ubuntu tutorial - IT technology blog
Ubuntu tutorial - IT technology blog

Introduction

If you work in internal IT support, you’re probably all too familiar with TeamViewer throwing a trial expiration warning right in the middle of a remote troubleshooting session. Worse yet, it flags “commercial use suspected” and drops your connection on the spot. AnyDesk has also been tightening its free-tier limits lately. And exposing RDP port 3389 directly to the internet? The risk of brute-force password attacks is way too high.

Our team switched completely to a self-hosted RustDesk Server to leave those headaches behind. It’s open-source, and since all traffic routes through our own server, we stay in full control of both latency and privacy. I tested this setup on an Ubuntu 22.04 staging environment before rolling it out to production. The entire stack has been running rock-solid for the past 6 months, using only around 50–80MB of RAM while keeping domestic ping under 15ms.

This guide documents every practical step: from spinning up the VPS and opening firewall ports to getting your clients connected.

Core Concepts

Understanding RustDesk’s architecture makes troubleshooting connection issues much faster. Unlike traditional VNC, which runs as a single service, RustDesk Server splits into two separate components running side by side:

  • hbbs (RustDesk ID/Rendezvous Server): Assigns IDs to client machines, tracks online/offline status, and coordinates P2P handshakes (hole punching). If two machines can reach each other directly over a LAN or a permissive NAT, the video stream travels peer-to-peer without consuming server bandwidth.
  • hbbr (RustDesk Relay Server): Acts as a traffic relay. When two devices sit behind strict NATs (such as 4G mobile networks or corporate firewalls that block P2P), all encrypted traffic is routed through hbbr.

Encryption and Public Key Authentication

On first startup, hbbs automatically generates an asymmetric key pair consisting of a Private Key (id_ed25519) and a Public Key (id_ed25519.pub). If you don’t enforce key authentication, anyone who knows your server’s IP address can freeload on your relay for remote sessions. That’s why in production, I always enable the -k _ flag to require every client to provide the matching Public Key before connecting.

Step-by-Step Setup

I chose Docker Compose over running raw binaries via systemd because it’s much easier to manage and upgrade down the road. All you need is a modest VPS with at least 1 vCPU and 1GB of RAM (around $4–5/month) running Ubuntu 22.04 or 24.04 with a static public IP. That’s plenty of headroom for a team of 30–50 machines.

Step 1: Install Docker and Open UFW Ports

SSH into your server and check if Docker and the Docker Compose plugin are already installed. If not, install them quickly with the following commands:

sudo apt update && sudo apt install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

Once Docker is ready, make sure to open the required ports in UFW (as well as your cloud provider’s Security Group or external firewall if you’re on AWS, GCP, or a similar Cloud VPS). This is the step people forget most often. RustDesk requires the following ports:

  • 21115 (TCP): Used by hbbs for NAT type testing.
  • 21116 (TCP & UDP): Main port for hbbs ID registration, heartbeat signals (UDP), and TCP hole punching.
  • 21117 (TCP): Used by hbbr for relay data transfer.
  • 21118, 21119 (TCP): Only needed if you plan to use the RustDesk Web Client.

Open the required ports on Ubuntu:

sudo ufw allow 21115/tcp
sudo ufw allow 21116/tcp
sudo ufw allow 21116/udp
sudo ufw allow 21117/tcp
sudo ufw reload
sudo ufw status

Step 2: Create the Docker Compose Configuration for RustDesk Server

I like to keep all self-hosted services under /opt for easy backups. Create the project directory and the docker-compose.yml file:

sudo mkdir -p /opt/rustdesk/data
cd /opt/rustdesk
sudo nano docker-compose.yml

Paste the configuration below into the file. Remember to replace YOUR_SERVER_IP_OR_DOMAIN with your server’s public IP or domain name (for example, remote.company.com):

services:
  hbbs:
    container_name: rustdesk-hbbs
    image: rustdesk/rustdesk-server:latest
    command: hbbs -r YOUR_SERVER_IP_OR_DOMAIN:21117 -k _
    volumes:
      - ./data:/root
    network_mode: "host"
    depends_on:
      - hbbr
    restart: unless-stopped

  hbbr:
    container_name: rustdesk-hbbr
    image: rustdesk/rustdesk-server:latest
    command: hbbr -k _
    volumes:
      - ./data:/root
    network_mode: "host"
    restart: unless-stopped

RustDesk officially recommends using network_mode: "host" to bypass Docker’s bridge NAT layer. This ensures P2P hole punching over UDP 21116 works reliably. The -k _ flag on both containers enforces key-based authentication using the key pair stored in ./data.

Step 3: Launch the Containers and Retrieve the Public Key

Pull the image and start the containers in detached mode:

sudo docker compose up -d

Check the logs to make sure neither container is throwing port conflicts or DNS resolution errors:

sudo docker compose logs -f --tail=50

When you see lines like Listening on tcp/0.0.0.0:21116 and Key: ..., the server is up and running. At this point, /opt/rustdesk/data will automatically contain the generated id_ed25519.pub file. Print its contents to get your Public Key string:

cat /opt/rustdesk/data/id_ed25519.pub

The string displayed (usually ending with an = sign) is the Key you’ll enter on your client machines. As for id_ed25519, that’s your Private Key—never share it with anyone. Be sure to back up this file so if you ever migrate servers, you won’t have to reconfigure the Key across all employee machines.

Step 4: Configure the RustDesk Client on User Machines

Download the RustDesk Client for Windows, macOS, or Linux from the project’s GitHub releases page. Open the app and follow these steps:

  1. Click the three-dot menu icon next to ID (or go to Settings → Network).
  2. Click Unlock network settings (requires administrator privileges).
  3. In the ID Server field: enter your server’s public IP or domain (e.g., remote.company.com).
  4. In the Relay Server field: leave it blank (since we already passed -r to hbbs) or enter the same IP/domain.
  5. In the Key field: paste the Public Key you retrieved in Step 3.
  6. Click Apply.

Head back to the main RustDesk screen. If you see a green dot with the word Ready in the bottom-left corner, your client has successfully connected to your private server. With a server hosted nearby (such as in Vietnam or Singapore), latency stays around 10–25ms, making mouse and keyboard input feel virtually instantaneous.

Quick Tip for Deploying to Multiple Team Machines

Manually installing the client and typing the Key on dozens of employee machines gets tedious fast. Fortunately, RustDesk lets you embed the server configuration directly into the Windows installer filename. Simply rename rustdesk-1.x.x-x86_64.exe to something like rustdesk-host=remote.company.com,key=YOUR_PUBLIC_KEY.exe, or push the configuration in bulk via PowerShell or GPO.

Conclusion

Setting up RustDesk Server on Ubuntu takes only about 10–15 minutes from start to finish. In return, your team no longer has to worry about licensing fees or sudden session disconnects like with free-tier proprietary tools. This Docker Compose setup with the -k _ flag keeps unauthorized users off your relay bandwidth while making backups as simple as archiving the /opt/rustdesk/data directory.

If you need centralized address book management or granular role-based permissions, you can consider upgrading to Server Pro. Additionally, restricting access to your office IP via UFW or placing the entire setup behind an internal VPN (like WireGuard) will harden your deployment even further.

Share: