Hello World

吞风吻雨葬落日 欺山赶海踏雪径

0%

ubuntu 22.04 install RustDesk-Server

rustdesk remote desktop software, written in Rust. Works out of the box, no configuration required. You have full control of your data, with no concerns about security.

服务端安装

服务端下载地址
https://github.com/rustdesk/rustdesk-server/releases

一键安装脚本
https://github.com/techahold/rustdeskinstall

服务端包含两个文件

  • hbbs - RustDesk ID/Rendezvous server
    • 默认监听:21115(TCP),21116(TCP/UDP), 21118(TCP)
  • hbbr - RustDesk Relay server
    • 默认监听:21117(TCP),21119(TCP)

端口说明

21115:是hbbs用作NAT类型测试,端口可以不开。
21116:TCP是hbbs用作TCP打洞与连接服务,UDP是hbbs用作ID注册与心跳服务。
21117:是hbbr用作中继服务使用。
21118、21119:是为了支持网页客户端。如果您不需要,端口可以不开。

如果只需要基本的远程控制,同时开启21116TCP和UDP,21117即可

服务配置
hbbs

1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]  
Description=RustDesk Hbbs
After=network.target

[Service]
User=forgives
Type=simple
WorkingDirectory=/home/forgives/apps/rustdesk-server
ExecStart=/home/forgives/apps/rustdesk-server/hbbs -k _
ExecStop=/bin/kill -TERM $MAINPID

[Install]
WantedBy=multi-user.target

hbbr

1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]  
Description=RustDesk Hbbr
After=network.target

[Service]
User=forgives
Type=simple
WorkingDirectory=/home/forgives/apps/rustdesk-server
ExecStart=/home/forgives/apps/rustdesk-server/hbbr -k _
ExecStop=/bin/kill -TERM $MAINPID

[Install]
WantedBy=multi-user.target

复制到 /etc/systemd/system/

1
2
sudo systemctl daemon-reload
sudo systemctl start hbbs.service

内网都不需要开中继服务。

直接安装

1
2
3
4
5
6
wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/install.sh
chmod +x install.sh
./install.sh

sudo systemctl restart rustdesksignal
sudo systemctl restart rustdeskrelay

key文件在 /opt/rustdesk 中。

参考: https://github.com/techahold/rustdeskinstall

客户端安装

客服端下载地址
https://github.com/rustdesk/rustdesk/releases

Linux

1
sudo apt install -f ./rustdesk-1.2.3-2-x86_64.deb

Windows

1
直接exe安装

设置

设置 -> 网络 -> 填写ID服务、中继服务器。key使用 服务端生成的idxxx.pub文件(hbbs服务首次启动的时候生成)的内容(服务端启动的时候一定要加上-k _参数)。

说明

rustdesksignal 信令服务器(Signaling Server),负责处理客户端之间的 连接建立与协调。
rustdeskrelay 中继服务器(Relay Server) ,它用于在客户端之间无法建立 P2P 连接时充当“中间人”,转发屏幕数据、控制指令等。

服务端安装脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
# Get Username
uname=$(whoami)
gname=$(id -gn ${uname})

ARCH=$(uname -m)

# identify OS
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID

UPSTREAM_ID=${ID_LIKE,,}

# Fallback to ID_LIKE if ID was not 'ubuntu' or 'debian'
if [ "${UPSTREAM_ID}" != "debian" ] && [ "${UPSTREAM_ID}" != "ubuntu" ]; then
UPSTREAM_ID="$(echo ${ID_LIKE,,} | sed s/\"//g | cut -d' ' -f1)"
fi
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
# Older SuSE/etc.
OS=SuSE
VER=$(cat /etc/SuSe-release)
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
OS=RedHat
VER=$(cat /etc/redhat-release)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi

echo "OS: $OS"
echo "VER: $VER"
echo "UPSTREAM_ID: $UPSTREAM_ID"

# Setup prereqs for server
# common named prereqs
PREREQ="curl wget unzip tar"
PREREQDEB="dnsutils"
PREREQRPM="bind-utils"
PREREQARCH="bind"

echo "Installing prerequisites"
if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ]; then
sudo apt-get update
sudo apt-get install -y ${PREREQ} ${PREREQDEB} # git
elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] ; then
# opensuse 15.4 fails to run the relay service and hangs waiting for it
# needs more work before it can be enabled
# || [ "${UPSTREAM_ID}" = "suse" ]
sudo yum update -y
sudo yum install -y ${PREREQ} ${PREREQRPM} # git
elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ]; then
sudo pacman -Syu
sudo pacman -S ${PREREQ} ${PREREQARCH}
else
echo "Unsupported OS"
# give them the option to continue
echo -n "Would you like to continue? Dependencies may not be satisfied... [y/n] "
read continue_no_dependencies
if [ $continue_no_dependencies == "y" ]; then
echo "Continuing..."
elif [ $continue_no_dependencies != "n" ]; then
echo "Invalid answer, exiting."
exit 1
else
exit 1
fi
fi

# Choice for DNS or IP
wanip=$(dig @resolver4.opendns.com myip.opendns.com +short)
if [ -z "$wanip" ]; then
echo "ERROR: 无法获取公网IP,请检查网络连接或手动设置wanip"
exit 1
fi

# Make Folder /opt/rustdesk/
if [ ! -d "/opt/rustdesk" ]; then
echo "Creating /opt/rustdesk"
sudo mkdir -p /opt/rustdesk/
fi
sudo chown "${uname}" -R /opt/rustdesk
cd /opt/rustdesk/ || exit 1

#Download latest version of Rustdesk
RDLATEST=$(curl https://api.github.com/repos/rustdesk/rustdesk-server/releases/latest -s | grep "tag_name" | awk -F'"' '{print $4}')

echo "Installing Rustdesk Server"
if [ "${ARCH}" = "x86_64" ] ; then
wget "https://github.com/rustdesk/rustdesk-server/releases/download/${RDLATEST}/rustdesk-server-linux-amd64.zip"
unzip rustdesk-server-linux-amd64.zip
mv amd64/* /opt/rustdesk/
elif [ "${ARCH}" = "armv7l" ] ; then
wget "https://github.com/rustdesk/rustdesk-server/releases/download/${RDLATEST}/rustdesk-server-linux-armv7.zip"
unzip rustdesk-server-linux-armv7.zip
mv armv7/* /opt/rustdesk/
elif [ "${ARCH}" = "aarch64" ] ; then
wget "https://github.com/rustdesk/rustdesk-server/releases/download/${RDLATEST}/rustdesk-server-linux-arm64v8.zip"
unzip rustdesk-server-linux-arm64v8.zip
mv arm64v8/* /opt/rustdesk/
fi

chmod +x /opt/rustdesk/hbbs
chmod +x /opt/rustdesk/hbbr

# Make Folder /var/log/rustdesk/
if [ ! -d "/var/log/rustdesk" ]; then
echo "Creating /var/log/rustdesk"
sudo mkdir -p /var/log/rustdesk/
fi
sudo chown "${uname}" -R /var/log/rustdesk/

# Setup Systemd to launch hbbs
rustdesksignal="$(cat << EOF
[Unit]
Description=Rustdesk Signal Server
[Service]
Type=simple
LimitNOFILE=1000000
ExecStart=/opt/rustdesk/hbbs
WorkingDirectory=/opt/rustdesk/
User=${uname}
Group=${gname}
Restart=always
StandardOutput=append:/var/log/rustdesk/signalserver.log
StandardError=append:/var/log/rustdesk/signalserver.error
# Restart service after 10 seconds if node service crashes
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
)"
echo "${rustdesksignal}" | sudo tee /etc/systemd/system/rustdesksignal.service > /dev/null
sudo systemctl daemon-reload
sudo systemctl enable rustdesksignal.service
sudo systemctl start rustdesksignal.service

# Setup Systemd to launch hbbr
rustdeskrelay="$(cat << EOF
[Unit]
Description=Rustdesk Relay Server
[Service]
Type=simple
LimitNOFILE=1000000
ExecStart=/opt/rustdesk/hbbr
WorkingDirectory=/opt/rustdesk/
User=${uname}
Group=${gname}
Restart=always
StandardOutput=append:/var/log/rustdesk/relayserver.log
StandardError=append:/var/log/rustdesk/relayserver.error
# Restart service after 10 seconds if node service crashes
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
)"
echo "${rustdeskrelay}" | sudo tee /etc/systemd/system/rustdeskrelay.service > /dev/null
sudo systemctl daemon-reload
sudo systemctl enable rustdeskrelay.service
sudo systemctl start rustdeskrelay.service

while ! [[ $CHECK_RUSTDESK_READY ]]; do
CHECK_RUSTDESK_READY=$(sudo systemctl status rustdeskrelay.service | grep "Active: active (running)")
echo -ne "Rustdesk Relay not ready yet...${NC}\n"
sleep 3
done

pubname=$(find /opt/rustdesk -name "*.pub")
key=$(cat "${pubname}")

echo "Tidying up install"
if [ "${ARCH}" = "x86_64" ] ; then
rm rustdesk-server-linux-amd64.zip
rm -rf amd64
elif [ "${ARCH}" = "armv7l" ] ; then
rm rustdesk-server-linux-armv7.zip
rm -rf armv7
elif [ "${ARCH}" = "aarch64" ] ; then
rm rustdesk-server-linux-arm64v8.zip
rm -rf arm64v8
fi

echo "Grabbing installers"
string="{\"host\":\"${wanip}\",\"relay\":\"${wanip}\",\"key\":\"${key}\",\"api\":\"https://${wanip}\"}"
string64=$(echo -n "$string" | base64 -w 0 | tr -d '=')
string64rev=$(echo -n "$string64" | rev)

echo "$string64rev"