
This article demonstrates how to deploy RustDesk on Ubuntu VPS for self-hosted AnyDesk alternative, enabling remote administration between remote computers.
What is RustDesk?
RustDesk is an open-source remote desktop tool—basically an alternative to AnyDesk or TeamViewer.
It lets you remotely view and control another computer over the internet for support, administration, or accessing your own machines. Its main appeal is that it can be self-hosted, meaning you can run your own RustDesk relay/rendezvous server instead of relying on a third-party remote-access provider.
Key points:
- Remote control: connect to another PC, Mac, Linux machine, Android device, etc.
- Open source: the main project is published publicly on GitHub.
- Self-hostable: useful for businesses that want control over remote-access infrastructure.
- Cross-platform: supports Windows, macOS, Linux, Android, and web/client options.
- Common use case: IT support, remote administration, unattended access, and replacing commercial tools like TeamViewer/AnyDesk.
For an MSP, hosting provider, or internal IT team, RustDesk is attractive because it reduces dependency on proprietary remote-access platforms while giving more control over privacy, routing, and infrastructure and reducing exposure to vendor lock-in.
This guide uses RustDesk Server OSS with Docker Compose on an Ubuntu VPS. RustDesk Server OSS runs two services: hbbs, the ID/rendezvous server, and hbbr, the relay server.
RustDesk clients normally try direct peer-to-peer connection first; if NAT traversal fails, traffic falls back through the relay server.
Prerequisites: What you need
You need:
- An Ubuntu VPS, preferably Ubuntu 22.04 or Ubuntu 24.04.
- Root or sudo access.
- A public IPv4 address.
- A DNS hostname such as
rustdesk.example.com, recommended. - Open firewall ports for RustDesk.
We will also recommend Docker Compose with network_mode: "host" for most Linux deployments because it is repeatable and avoids Docker port-mapping issues.
For this guide, replace rustdesk.example.com with your real DNS hostname or VPS public IP.
Compare Ubuntu VPS Plans
Deploy RustDesk on Ubuntu VPS for Self-Hosted AnyDesk Alternative
To deploy RustDesk on Ubuntu VPS for self-hosted AnyDesk alternative, follow the steps provided below:
-
Prepare the Ubuntu VPS
-
Point DNS to your VPS
Create an A record:
rustdesk.example.com -> YOUR_VPS_PUBLIC_IP
Wait for DNS to propagate, then test from your local computer:
ping rustdesk.example.com
On the VPS, you can also check:
dig rustdesk.example.com
If you do not have DNS, you can use the VPS public IP directly in RustDesk clients.
-
Log in to the VPS
From your local machine:
ssh root@YOUR_VPS_PUBLIC_IP
Or, if using a sudo user:
ssh youruser@YOUR_VPS_PUBLIC_IP
Update the server:
sudo apt update sudo apt upgrade -y
Install basic utilities:
sudo apt install -y ca-certificates curl gnupg lsb-release ufw
-
-
Install Docker and Docker Compose
-
Install Docker
Install Docker from Ubuntu’s package repositories:
sudo apt-get update sudo apt-get install 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-get update sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Enable Docker at boot:
sudo systemctl enable docker sudo systemctl start docker
Check Docker:
docker --version docker compose version
Optional: allow your non-root user to run Docker:
sudo usermod -aG docker $USER
Then log out and log back in.
-
-
Open the required firewall ports
RustDesk Server OSS uses the following core ports:
Port Protocol Service Purpose 21115 TCP hbbs NAT type test 21116 TCP hbbs TCP hole punching and connection service 21116 UDP hbbs ID registration and heartbeat 21117 TCP hbbr Relay service 21118 TCP hbbs Web client support (optional) 21119 TCP hbbr Web client support (optional) Open the ports with UFW:
sudo ufw allow OpenSSH sudo ufw allow 21115/tcp sudo ufw allow 21116/tcp sudo ufw allow 21116/udp sudo ufw allow 21117/tcp sudo ufw allow 21118/tcp sudo ufw allow 21119/tcp sudo ufw enable
Check status:
sudo ufw status verbose
Also make sure your VPS provider’s external firewall/security group allows the same ports.
-
Deploy RustDesk Server
-
Create a RustDesk server directory
sudo mkdir -p /opt/rustdesk-server/data cd /opt/rustdesk-server
Set ownership to your current user if needed:
sudo chown -R $USER:$USER /opt/rustdesk-server
-
Create the Docker Compose file
Create the file:
nano compose.yml
Paste this:
services: hbbs: container_name: hbbs image: rustdesk/rustdesk-server:latest command: hbbs volumes: - ./data:/root network_mode: "host" depends_on: - hbbr restart: unless-stopped hbbr: container_name: hbbr image: rustdesk/rustdesk-server:latest command: hbbr volumes: - ./data:/root network_mode: "host" restart: unless-stoppedThis follows RustDesk’s official Docker Compose pattern for
hbbsandhbbrusing a shared persistent data folder.Save and exit.
-
Start RustDesk Server
Run:
docker compose up -d
Check containers:
docker compose ps
You should see both containers running:
hbbs hbbr
View logs:
docker logs hbbs docker logs hbbr
-
-
Get the RustDesk server public key
RustDesk generates the server key on the first run. The public key is normally stored in:
/opt/rustdesk-server/data/id_ed25519.pub
Show it:
cat /opt/rustdesk-server/data/id_ed25519.pub
Copy the full output.
RustDesk clients need this public key for encrypted connections to your self-hosted server. The official client configuration docs state that the key is usually generated on the first run of
hbbsand found inid_ed25519.pubin the working directory or data folder.Example:
u1xzHkxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
Keep this value ready for the Windows and macOS clients.
-
Verify the server is listening
Run:
ss -tulpn | grep 211
You should see listeners for RustDesk ports such as:
21115 21116 21117 21118 21119
You can also test from another Linux/macOS machine:
nc -vz rustdesk.example.com 21116 nc -vz rustdesk.example.com 21117
For UDP
21116, use:nc -vzu rustdesk.example.com 21116
-
Connect a Windows client
-
Install RustDesk on Windows
Download the Windows client from RustDesk’s official releases/download page. The current release page provides Windows, macOS, Linux, Android, iOS, and web builds.
On Windows:
- Download the Windows
.exeor.msi. - Run the installer.
- Open RustDesk.
- Install the service if you want unattended access or remote access before login.
- Note the Windows machine’s RustDesk ID and one-time password.
- Download the Windows
-
Configure the Windows client to use your server
On the Windows RustDesk client:
- Open RustDesk.
- Click the menu button near your ID, usually the three dots.
- Go to Settings.
- Open Network.
- Click Unlock Network Settings.
- Enter:
ID Server: rustdesk.example.com Relay Server: rustdesk.example.com API Server: leave blank for OSS Key: paste contents of id_ed25519.pub
Fill the rustdesk server details inside the rustdesk client Most self-hosted clients need the ID Server and Key; the relay server is often optional because RustDesk can infer it, but setting it explicitly is fine. API Server is mainly for RustDesk Server Pro.
Click Apply.
The bottom of the client should show something like:
Ready
-
Set unattended access on Windows
On the Windows machine:
- Open Settings.
- Go to Security.
- Enable or set a permanent password.
- Keep RustDesk running.
- Confirm the RustDesk service is installed if you need access when no user is logged in.
You now have:
Windows RustDesk ID Windows permanent password
-
-
Connect a macOS client
-
Install RustDesk on macOS
Download the macOS
.dmgfrom RustDesk’s releases/download page. Choose the correct build for your Mac:- Apple Silicon / ARM64 for M1, M2, M3, M4 Macs.
- x86_64 / Intel for older Intel Macs.
- Universal if offered and you are unsure.
Install it:
- Open the
.dmg. - Drag RustDesk into Applications.
- Open RustDesk from Applications.
macOS usually requires additional permissions before RustDesk can show or control the screen. You typically need to move the app into Applications, allow it to run, and grant Accessibility, Screen Recording, and sometimes Input Monitoring permissions. Grant macOS permissions.
- On the Mac:
- Open System Settings.
- Go to Privacy & Security.
- Open Accessibility.
- Enable RustDesk.
- Go back to Privacy & Security.
- Open Screen Recording.
- Enable RustDesk.
- If prompted or needed, also enable Input Monitoring for RustDesk.
- Quit and reopen RustDesk.
Without these permissions, you may connect to the Mac but be unable to see the screen, control the mouse, or type.
-
Configure the macOS client to use your server
On the Mac RustDesk client:
- Open RustDesk.
- Click the menu button near your ID.
- Go to Settings.
- Open Network.
- Click Unlock Network Settings.
- Enter:
ID Server: rustdesk.example.com Relay Server: rustdesk.example.com API Server: leave blank for OSS Key: paste contents of id_ed25519.pub
Click Apply.
The client should show:
Ready
-
Set unattended access on macOS
On the Mac:
- Open RustDesk.
- Go to Settings.
- Open Security.
- Set a permanent password.
- Confirm RustDesk remains running.
- Confirm macOS permissions are still enabled after reopening the app.
You now have:
macOS RustDesk ID macOS permanent password
-
-
Connect Windows and macOS to each other
You can connect in either direction.
-
Option A: Connect from Windows to Mac
On the Windows client:
- Open RustDesk.
- Enter the Mac’s RustDesk ID.
- Click Connect.
- Enter the Mac’s one-time password or permanent password.
- Accept the session on the Mac if prompted.
-
Option B: Connect from Mac to Windows
On the Mac client:
- Open RustDesk.
- Enter the Windows machine’s RustDesk ID.
- Click Connect.
- Enter the Windows one-time password or permanent password.
- Accept the session on Windows if prompted.
Both clients must use the same:
ID Server Relay Server Key
-
-
Useful administration commands
-
Check RustDesk server status
cd /opt/rustdesk-server docker compose ps
-
View logs
docker logs hbbs --tail 100 docker logs hbbr --tail 100
-
Restart RustDesk Server
cd /opt/rustdesk-server docker compose restart
-
Stop RustDesk Server
cd /opt/rustdesk-server docker compose down
-
Start RustDesk Server again
cd /opt/rustdesk-server docker compose up -d
-
Update RustDesk Server
cd /opt/rustdesk-server docker compose pull docker compose up -d
-
Back up the server keys
Back up this directory:
/opt/rustdesk-server/data
Especially these files:
id_ed25519 id_ed25519.pub
Do not lose them. If the server key changes, all clients using the old key will need to be reconfigured.
Create a backup:
sudo tar -czvf rustdesk-server-backup.tar.gz /opt/rustdesk-server/data
-
-
Troubleshooting
-
Client says “Not ready” or cannot connect to server
Check:
docker compose ps docker logs hbbs --tail 100 docker logs hbbr --tail 100 sudo ufw status
Verify that your VPS firewall allows:
TCP 21115 TCP 21116 UDP 21116 TCP 21117 TCP 21118 TCP 21119
At minimum, RustDesk needs
21115-21117and UDP21116;21118and21119are for web client support. -
Client shows key mismatch
Re-copy the public key:
cat /opt/rustdesk-server/data/id_ed25519.pub
Paste it into each RustDesk client’s Key field.
Make sure you did not paste extra spaces or line breaks.
-
Direct connection fails but relay works
That is normal in some NAT/firewall environments. RustDesk tries hole punching first and falls back to
hbbrrelay if direct connection fails. -
macOS connects but cannot be controlled
Recheck macOS permissions:
System Settings → Privacy & Security → Accessibility System Settings → Privacy & Security → Screen Recording System Settings → Privacy & Security → Input Monitoring
Then quit and reopen RustDesk.
-
Windows connects but cannot control elevated/admin windows
Install RustDesk as a service and run it with appropriate privileges. For unattended support, the service installation is usually required.
-
Recommended final setup
Use this client configuration on both Windows and macOS:
ID Server: rustdesk.example.com Relay Server: rustdesk.example.com API Server: blank Key: contents of /opt/rustdesk-server/data/id_ed25519.pub
Use this server layout:
/opt/rustdesk-server/
├── compose.yml
└── data/
├── id_ed25519
└── id_ed25519.pub
Once both clients show Ready, enter one device’s RustDesk ID into the other device and connect.
Conclusion
You now know how to deploy RustDesk on Ubuntu VPS for self-hosted AnyDesk alternative and connect two remote computers allowing remote administration.










