Files
doc.rustdesk.com/content/self-host/client-deployment/_index.zh-cn.md
T
2026-06-11 22:39:03 +08:00

422 lines
14 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: 客户端部署
weight: 400
pre: "<b>2.4. </b>"
description: "RustDesk 的客户端部署文档,提供安装、配置、部署和故障排查指南。"
keywords: ["rustdesk client deployment", "rustdesk powershell deploy", "rustdesk mass deployment", "rustdesk intune", "rustdesk rmm", "rustdesk silent deployment"]
---
<!-- GEO-LOCALIZED-INTRO:START -->
## 快速回答
在大规模部署中,最好使用脚本、MSI 包或 RMM/MDM 工具,让 RustDesk 自动以正确的服务器配置完成安装。最适合的方法主要取决于您的操作系统和现有管理工具链。
## 关键要点
- 服务器主机名或 `ID Server` 地址
- 自托管服务器的公钥
- 用于 Pro 登录的可选 `API Server`
- 适合您现有工具的配置字符串或打包方式
<!-- GEO-LOCALIZED-INTRO:END -->
最简单的方法是使用自定义客户端,https://twitter.com/rustdesk/status/1788905463678951787。
您可以使用多种方法进行部署,其中一些在[客户端配置](https://rustdesk.com/docs/en/self-host/client-configuration/)中有介绍。
或者,您可以通过 RMM、Intune 等使用批量部署脚本。ID 和密码由脚本输出。您应该收集这些信息或将其拆分为不同的脚本来收集 ID 和密码。
可以通过将 `rustdesk_pw` 后面 `()` 内的内容更改为您首选的密码来将永久密码从随机更改为您首选的密码,这适用于 PowerShell,其他平台的相应行也是如此。
## PowerShell
```powershell
$ErrorActionPreference= 'silentlycontinue'
# 为密码变量分配随机密码值
$rustdesk_pw=(-join ((65..90) + (97..122) | Get-Random -Count 12 | % {[char]$_}))
# 从您的 Web 门户获取配置字符串并填写下面
$rustdesk_cfg="configstring"
################################## 请不要编辑此行以下的内容 #########################################
# 以管理员身份运行并保持在当前目录
if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000)
{
Start-Process PowerShell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
Exit;
}
}
# 此函数将返回最新版本和下载链接作为对象
function getLatest()
{
$Page = Invoke-WebRequest -Uri 'https://github.com/rustdesk/rustdesk/releases/latest' -UseBasicParsing
$HTML = New-Object -Com "HTMLFile"
try
{
$HTML.IHTMLDocument2_write($Page.Content)
}
catch
{
$src = [System.Text.Encoding]::Unicode.GetBytes($Page.Content)
$HTML.write($src)
}
# 当前示例链接: https://github.com/rustdesk/rustdesk/releases/download/1.2.6/rustdesk-1.2.6-x86_64.exe
$Downloadlink = ($HTML.Links | Where {$_.href -match '(.)+\/rustdesk\/rustdesk\/releases\/download\/\d{1}.\d{1,2}.\d{1,2}(.{0,3})\/rustdesk(.)+x86_64.exe'} | select -first 1).href
# 错误修复 - 有时需要替换 "about:"
$Downloadlink = $Downloadlink.Replace('about:', 'https://github.com')
$Version = "unknown"
if ($Downloadlink -match './rustdesk/rustdesk/releases/download/(?<content>.*)/rustdesk-(.)+x86_64.exe')
{
$Version = $matches['content']
}
if ($Version -eq "unknown" -or $Downloadlink -eq "")
{
Write-Output "错误:未找到版本或下载链接。"
Exit
}
# 创建要返回的对象
$params += @{Version = $Version}
$params += @{Downloadlink = $Downloadlink}
$Result = New-Object PSObject -Property $params
return($Result)
}
$RustDeskOnGitHub = getLatest
$rdver = ((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RustDesk\").Version)
if ($rdver -eq $RustDeskOnGitHub.Version)
{
Write-Output "RustDesk $rdver 是最新版本。"
Exit
}
if (!(Test-Path C:\Temp))
{
New-Item -ItemType Directory -Force -Path C:\Temp | Out-Null
}
cd C:\Temp
Invoke-WebRequest $RustDeskOnGitHub.Downloadlink -Outfile "rustdesk.exe"
Start-Process .\rustdesk.exe --silent-install
Start-Sleep -seconds 20
$ServiceName = 'Rustdesk'
$arrService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($arrService -eq $null)
{
Write-Output "正在安装服务"
cd $env:ProgramFiles\RustDesk
Start-Process .\rustdesk.exe --install-service
Start-Sleep -seconds 20
$arrService = Get-Service -Name $ServiceName
}
while ($arrService.Status -ne 'Running')
{
Start-Service $ServiceName
Start-Sleep -seconds 5
$arrService.Refresh()
}
cd $env:ProgramFiles\RustDesk\
.\rustdesk.exe --get-id | Write-Output -OutVariable rustdesk_id
.\rustdesk.exe --config $rustdesk_cfg
.\rustdesk.exe --password $rustdesk_pw
Write-Output "..............................................."
# 显示 ID 变量的值
Write-Output "RustDesk ID: $rustdesk_id"
# 显示密码变量的值
Write-Output "密码: $rustdesk_pw"
Write-Output "..............................................."
```
## Windows 批处理/cmd
```bat
@echo off
REM 为密码变量分配随机密码值
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set alfanum=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
set rustdesk_pw=
for /L %%b in (1, 1, 12) do (
set /A rnd_num=!RANDOM! %% 62
for %%c in (!rnd_num!) do (
set rustdesk_pw=!rustdesk_pw!!alfanum:~%%c,1!
)
)
REM 从您的 Web 门户获取配置字符串并填写下面
set rustdesk_cfg="configstring"
REM ############################### 请不要编辑此行以下的内容 #########################################
if not exist C:\Temp\ md C:\Temp\
cd C:\Temp\
curl -L "https://github.com/rustdesk/rustdesk/releases/download/1.2.6/rustdesk-1.2.6-x86_64.exe" -o rustdesk.exe
rustdesk.exe --silent-install
timeout /t 20
cd "C:\Program Files\RustDesk\"
rustdesk.exe --install-service
timeout /t 20
for /f "delims=" %%i in ('rustdesk.exe --get-id ^| more') do set rustdesk_id=%%i
rustdesk.exe --config %rustdesk_cfg%
rustdesk.exe --password %rustdesk_pw%
echo ...............................................
REM 显示 ID 变量的值
echo RustDesk ID: %rustdesk_id%
REM 显示密码变量的值
echo 密码: %rustdesk_pw%
echo ...............................................
```
## MSI
您也可以使用 msi 而不是 `rustdesk.exe --silent-install`
https://rustdesk.com/docs/en/client/windows/msi/
## macOS Bash
```sh
#!/bin/bash
# 为密码变量分配随机密码值
rustdesk_pw=$(openssl rand -hex 4)
# 从您的 Web 门户获取配置字符串并填写下面
rustdesk_cfg="configstring"
################################## 请不要编辑此行以下的内容 #########################################
# 请求 root 密码以进行权限提升
[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@"
# 指定 DMG 的挂载点(临时目录)
mount_point="/Volumes/RustDesk"
# 下载 rustdesk.dmg 文件
echo "正在下载 RustDesk"
if [[ $(arch) == 'arm64' ]]; then
rd_link=$(curl -sL https://github.com/rustdesk/rustdesk/releases/latest | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*/\d{1}.\d{1,2}.\d{1,2}/rustdesk.\d{1}.\d{1,2}.\d{1,2}.aarch64.dmg")
dmg_file=$(echo $rd_link | grep -Eo "rustdesk.\d{1}.\d{1,2}.\d{1,2}.aarch64.dmg")
curl -L "$rd_link" --output "$dmg_file"
else
rd_link=$(curl -sL https://github.com/rustdesk/rustdesk/releases/latest | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*/\d{1}.\d{1,2}.\d{1,2}/rustdesk.\d{1}.\d{1,2}.\d{1,2}.x86_64.dmg")
dmg_file=$(echo $rd_link | grep -Eo "rustdesk.\d{1}.\d{1,2}.\d{1,2}.x86_64.dmg")
curl -L "$rd_link" --output "$dmg_file"
fi
# 将 DMG 文件挂载到指定的挂载点
hdiutil attach "$dmg_file" -mountpoint "$mount_point" &> /dev/null
# 检查挂载是否成功
if [ $? -eq 0 ]; then
# 将挂载的 DMG 内容移动到 /Applications 文件夹
cp -R "$mount_point/RustDesk.app" "/Applications/" &> /dev/null
# 卸载 DMG 文件
hdiutil detach "$mount_point" &> /dev/null
else
echo "挂载 RustDesk DMG 失败。安装中止。"
exit 1
fi
# 运行 rustdesk 命令带 --get-id 并将输出存储在 rustdesk_id 变量中
cd /Applications/RustDesk.app/Contents/MacOS/
rustdesk_id=$(./RustDesk --get-id)
# 为 RustDesk 应用新密码
./RustDesk --server &
/Applications/RustDesk.app/Contents/MacOS/RustDesk --password $rustdesk_pw &> /dev/null
/Applications/RustDesk.app/Contents/MacOS/RustDesk --config $rustdesk_cfg
# 终止所有名为 RustDesk 的进程
rdpid=$(pgrep RustDesk)
kill $rdpid &> /dev/null
echo "..............................................."
# 检查 rustdesk_id 是否不为空
if [ -n "$rustdesk_id" ]; then
echo "RustDesk ID: $rustdesk_id"
else
echo "获取 RustDesk ID 失败。"
fi
# 回显密码变量的值
echo "密码: $rustdesk_pw"
echo "..............................................."
echo "请在 GUI 上完成安装,现在启动 RustDesk。"
open -n /Applications/RustDesk.app
```
## Linux
```sh
#!/bin/bash
# 为密码变量分配随机值
rustdesk_pw=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)
# 从您的 Web 门户获取配置字符串并填写下面
rustdesk_cfg="configstring"
################################## 请不要编辑此行以下的内容 #########################################
# 检查脚本是否以 root 身份运行
if [[ $EUID -ne 0 ]]; then
echo "此脚本必须以 root 身份运行。"
exit 1
fi
# 识别操作系统
if [ -f /etc/os-release ]; then
# freedesktop.org 和 systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
UPSTREAM_ID=${ID_LIKE,,}
# 如果 ID 不是 'ubuntu' 或 'debian',则回退到 ID_LIKE
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
# 对于一些没有 lsb_release 命令的 Debian/Ubuntu 版本
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# 较旧的 Debian、Ubuntu 等
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSE-release ]; then
# 较旧的 SuSE 等
OS=SuSE
VER=$(cat /etc/SuSE-release)
elif [ -f /etc/redhat-release ]; then
# 较旧的 Red Hat、CentOS 等
OS=RedHat
VER=$(cat /etc/redhat-release)
else
# 回退到 uname,例如 "Linux <version>",也适用于 BSD 等
OS=$(uname -s)
VER=$(uname -r)
fi
# 安装 RustDesk
echo "正在安装 RustDesk"
if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ]; then
wget https://github.com/rustdesk/rustdesk/releases/download/1.2.6/rustdesk-1.2.6-x86_64.deb
apt-get install -fy ./rustdesk-1.2.6-x86_64.deb > null
elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "$OS" = "Fedora Linux" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "$OS" = "Almalinux" ] || [ "$OS" = "Rocky*" ] ; then
wget https://github.com/rustdesk/rustdesk/releases/download/1.2.6/rustdesk-1.2.6-0.x86_64.rpm
yum localinstall ./rustdesk-1.2.6-0.x86_64.rpm -y > null
else
echo "不支持的操作系统"
# 这里您可以询问用户是否允许尝试安装
# 如果他们说是,则进行安装
# 如果他们说否,退出脚本
exit 1
fi
# 运行 rustdesk 命令带 --get-id 并将输出存储在 rustdesk_id 变量中
rustdesk_id=$(rustdesk --get-id)
# 为 RustDesk 应用新密码
rustdesk --password $rustdesk_pw &> /dev/null
rustdesk --config $rustdesk_cfg
systemctl restart rustdesk
echo "..............................................."
# 检查 rustdesk_id 是否不为空
if [ -n "$rustdesk_id" ]; then
echo "RustDesk ID: $rustdesk_id"
else
echo "获取 RustDesk ID 失败。"
fi
# 回显密码变量的值
echo "密码: $rustdesk_pw"
echo "..............................................."
```
## 新设备的显式部署
默认情况下,RustDesk 客户端首次连接到自建服务器时会注册到该服务器。普通模式下不需要额外的部署步骤。
如果在服务器 Web 控制台中启用 **设置 → 其他 → 新设备必须部署后注册**,新设备必须先显式部署,才能注册到此服务器。
使用管理员账号在服务器 Web 控制台中创建 [API token](/docs/en/self-host/rustdesk-server-pro/console/#api-token)。该 token 必须具有 **设备****读写** 权限。然后在每台新的桌面设备上安装 RustDesk,并配置为使用你的自建服务器后,运行部署命令。
### Windows、macOS 和 Linux
在 Windows 上,以管理员身份运行命令提示符或 PowerShell
```bat
rustdesk --deploy --token <api_token>
```
在 macOS 和 Linux 上,使用 `sudo` 运行命令:
```sh
sudo rustdesk --deploy --token <api_token>
```
### 可选的自定义 ID
如需使用指定的 RustDesk ID 部署设备,请添加 `--id <custom_id>`
```sh
rustdesk --deploy --token <api_token> --id <custom_id>
```
如果该 ID 已被另一台设备使用,部署会失败,RustDesk 会提示该 ID 已被占用。
### Android
Android 不使用命令行部署流程。当服务器要求部署且 Android 客户端尚未部署时,RustDesk 会显示 **部署** 提示。点击 **确定**,在部署对话框中输入 API token,并可选择输入自定义 ID。也可以从 **设置 → 部署** 手动打开同一个对话框。
部署成功后,设备会添加到服务器设备列表中,客户端即可正常注册。