How to Use RustDesk with Self-hosted Server¶
Link¶
-
RustDesk
A free and open-source remote desktop software, featuring support for self-hosted server.
What is RustDesk¶
RustDesk is a free and open-source remote desktop software. It is cross-platform and supports Windows, MacOS, and Linux. It is very easy to use and has a very friendly user interface. The most outstanding feature of RustDesk is that it supports self-hosted server. You can build your own server and use it to connect to your remote machine. This is very useful for those who want to control their remote machine but don't want to use public server.
Client Installation and Use¶
The focus of this article is how to build your own server and use it to connect to your remote machine. Check the github link for client downloading and the official guide for installation and use.
Before We Start¶
I assume you have a cloud server running Linux. If you don't have one, you can follow the this article.
References and Resources¶
Start of Our Journey¶
We start from Here!
Connect to Your Server via SSH¶
In my case I use MobaXterm to connect to my server via SSH. You can use any SSH client you like, for example, Termius, PuTTY, etc.
Make a Directory for RustDesk¶
For my case, I made a directory called RUSTDESK-Sever
in root directory /
. To do that, run the following command:
then
and then go to the directory:
Download RustDesk Server¶
Go to the ๐ RustDesk Server Release Page and pick the corresponding version for your server. For my case, I picked rustdesk-server-linux-amd64.zip
and downloaded it to my server.
Right click on the downloaded file and copy the link address. Then run the following command to download it to your server:
In my case, I ran the following command:
wget https://github.com/rustdesk/rustdesk-server/releases/download/1.1.9/rustdesk-server-linux-amd64fb.zip
Then run the following command to unzip the file:
After unzipping the file, you will see a folder called amd64
. For convenience, lets rename it to RustDesk
:
Try to Run RustDesk Server with Screen¶
What is Screen¶
Screen is a terminal multiplexer. It allows you to run multiple terminal sessions inside one terminal window. It is very useful when you want to run a program in the background and don't want to keep the terminal window open. You can just detach the screen and close the terminal window. The program will keep running in the background. You can also reattach the screen and check the program's output.
Install Screen¶
Check the Contents of the Folder with 'tree'¶
First, we need to install tree
:
Then run the following command to check the contents of the folder:
You will see the following output:
Info
hbbr
is the for relay server.hbbs
is the for ID server.rustdesk-utils
is a utility program.
Run Screen and RustDesk Server¶
Now, we can use two Screens to run RustDesk hbbr and hbbs. First, run the following command to create a new Screen:
Then run the following command to start RustDesk hbbr:
Then you will see some printouts on the screen if this step is successful. Then press Ctrl + A + D
to detach the screen. Then run the following command to create a new Screen:
Then run the following command to start RustDesk hbbs:
Then you will see some printouts on the screen if this step is successful. Then press Ctrl + A + D
to detach the screen. Then run the following command to check the running screens:
You will see something like:
Copy the Public Key for Client Configuration¶
Now we can check the contents with tree
again:
You will see the following output:
.
โโโ RustDesk
โย ย โโโ db_v2.sqlite3
โย ย โโโ db_v2.sqlite3-shm
โย ย โโโ db_v2.sqlite3-wal
โย ย โโโ hbbr
โย ย โโโ hbbs
โย ย โโโ id_ed25519
โย ย โโโ id_ed25519.pub
โย ย โโโ rustdesk-utils
โโโ rustdesk-server-linux-amd64.zip
The key is in id_ed25519.pub
. Run the following command to print the key:
or the command below:
Copy the key and save it somewhere. We will use it later.
Firewall Configuration¶
In your cloud server backend, you need to open the following ports: - 21115 for TCP - 21116 for TCP & UDP - 21117 for TCP - 21118 for TCP - 21119 for TCP
If necessary, you also need to open the above ports in your OS firewall. (try first without this step)
Clients Configuration and Connection¶
Ingredients for client configuration: - Server IP address - Public key
I assume you have installed RustDesk client on your local machine. If you haven't, please check the official guide for installation and use.
Open RustDesk client and find the ID of your computer in the column on the lefthand side. Then click the three dots button and then select the Network
tab.
- For
ID Server
, input the IP address of your server. This is for hbbs. - For
Relay Server
, also input the IP address of your server. This is for hbbr. - For
API Server
, you can keep it blank. - For
Key
, input the public key you copied from your server.
The above procedures are same for both the PC to control and the PC to be controlled.
On the PC to start the connection, input the ID of the PC to be controlled and click Connect
. Then you will see a window pop up. Input the password of the PC to be controlled and click OK
. Then you will see the desktop of the PC to be controlled.
So far, we have successfully connected to the PC to be controlled. But we still need to do some configuration to make this process more elegant.
Run RustDesk Server as a Service¶
The reason why we need to do this step is that we don't want to run RustDesk Server manually every time we restart our server. We want it to run automatically when the server starts.
There are two ways to do this: 1. Use pm2 2. Use systemd
Use pm2¶
This is the way recommended by the official guide. But I did not try this myself. Here are the steps you can follow:
First, you need to install nodejs and npm:
Then install pm2:
Then run the following command to start RustDesk Server:
Then run the following command to make pm2 run as a service:
Use systemd¶
This is the way I tried myself. We need to create two service files for hbbr and hbbs respectively.
For hbbs
First, create a file called RustDeskHbbs.service
in /usr/lib/systemd/system/
:
Then copy the following content to the file:
Note
Do modify the contents in <...>
according to your own situation.
[Unit]
Description=RustDesk Hbbs
After=network.target
[Service]
User=<your user name>
Type=simple
WorkingDirectory=<directory where you put RustDesk Server>
ExecStart=<directory where you put RustDesk Server>/hbbs
ExecStop=/bin/kill -TERM $MAINPID
[Install]
WantedBy=multi-user.target
For hbbr
First, create a file called RustDeskHbbr.service
in /usr/lib/systemd/system/
:
Then copy the following content to the file:
Note
Do modify the contents in <...>
according to your own situation.
[Unit]
Description=RustDesk Hbbr
After=network.target
[Service]
User=<your user name>
Type=simple
WorkingDirectory=<directory where you put RustDesk Server>
ExecStart=<directory where you put RustDesk Server>/hbbr
ExecStop=/bin/kill -TERM $MAINPID
[Install]
WantedBy=multi-user.target
Then run the following command to start RustDesk Server:
or reload the systemd configuration:
Enable Force Encryption¶
You can modify the service file to enable force encryption.
For hbbs reopen the service file:
Then modify the ExecStart
line to:
[Unit]
Description=RustDesk Hbbs
After=network.target
[Service]
User=<your user name>
Type=simple
WorkingDirectory=<directory where you put RustDesk Server>
ExecStart=<directory where you put RustDesk Server>/hbbs -k _
ExecStop=/bin/kill -TERM $MAINPID
[Install]
WantedBy=multi-user.target
For hbbr reopen the service file:
Then modify the ExecStart
line to:
[Unit]
Description=RustDesk Hbbr
After=network.target
[Service]
User=<your user name>
Type=simple
WorkingDirectory=<directory where you put RustDesk Server>
ExecStart=<directory where you put RustDesk Server>/hbbr -k _
ExecStop=/bin/kill -TERM $MAINPID
[Install]
WantedBy=multi-user.target
Additional Client Configuration¶
Sometimes, you need to grant access to Rustdesk to enable some functions. On Mac, you may need to enable accessibility for Rustdesk in System Preferences
-> Security & Privacy
-> Privacy
-> Accessibility
. On windows, you may need to install a full version of Rustdesk to enable some functions. In both cases, there will be a reminder at the left part of the Rustdesk GUI.
The End.