Fix Linux RustDesk permanent password handling
This commit is contained in:
@@ -177,16 +177,23 @@ serial = 0
|
||||
custom-rendezvous-server = '${RUSTDESK_SERVER_ADDRESS}:21116'
|
||||
relay-server = '${RUSTDESK_SERVER_ADDRESS}:21117'
|
||||
key = '${RUSTDESK_SERVER_PUBLIC_KEY}'
|
||||
verification-method = 'use-permanent-password'
|
||||
EOF
|
||||
)
|
||||
|
||||
# The Linux service runs as root. Keep the system copy as a diagnostic and
|
||||
# the root profile copy as the configuration consumed by the service.
|
||||
# The service starts as root but RustDesk hands its graphical server to the
|
||||
# LightDM session account. Configure both profiles; writing only root's
|
||||
# profile leaves the greeter-side server using a temporary password.
|
||||
install -d -o root -g root -m 700 /root/.config/rustdesk /etc/rustdesk
|
||||
printf '%s\n' "$configuration" | install -o root -g root -m 600 /dev/stdin \
|
||||
/root/.config/rustdesk/RustDesk2.toml
|
||||
printf '%s\n' "$configuration" | install -o root -g root -m 644 /dev/stdin \
|
||||
/etc/rustdesk/RustDesk2.toml
|
||||
if id lightdm >/dev/null 2>&1; then
|
||||
install -d -o lightdm -g lightdm -m 700 /var/lib/lightdm/.config/rustdesk
|
||||
printf '%s\n' "$configuration" | install -o lightdm -g lightdm -m 600 /dev/stdin \
|
||||
/var/lib/lightdm/.config/rustdesk/RustDesk2.toml
|
||||
fi
|
||||
|
||||
systemctl restart rustdesk
|
||||
systemctl is-active --quiet rustdesk || fail 'The RustDesk service did not start.'
|
||||
@@ -194,16 +201,34 @@ EOF
|
||||
|
||||
set_access_password() {
|
||||
local secret_path="${STATE_ROOT}/access.secret"
|
||||
if [[ -r $secret_path ]]; then
|
||||
if [[ -r $secret_path ]] && [[ $(wc -c <"$secret_path") -le 32 ]]; then
|
||||
ACCESS_PASSWORD=$(<"$secret_path")
|
||||
else
|
||||
ACCESS_PASSWORD=$(openssl rand -hex 24)
|
||||
# RustDesk's permanent-password UI is reliable with a short, printable
|
||||
# credential. Earlier Linux enrollment generated 48 hexadecimal
|
||||
# characters; rotate that legacy value to a 24-character password.
|
||||
ACCESS_PASSWORD="Sgu-$(openssl rand -hex 10)"
|
||||
umask 077
|
||||
printf '%s' "$ACCESS_PASSWORD" >"$secret_path"
|
||||
chmod 600 "$secret_path"
|
||||
fi
|
||||
|
||||
rustdesk --password "$ACCESS_PASSWORD" >/dev/null
|
||||
rustdesk --option verification-method use-permanent-password >/dev/null
|
||||
if id lightdm >/dev/null 2>&1; then
|
||||
local lightdm_uid
|
||||
lightdm_uid=$(id -u lightdm)
|
||||
runuser -u lightdm -- env HOME=/var/lib/lightdm \
|
||||
XDG_CONFIG_HOME=/var/lib/lightdm/.config \
|
||||
XDG_RUNTIME_DIR="/run/user/${lightdm_uid}" \
|
||||
/usr/share/rustdesk/rustdesk --password "$ACCESS_PASSWORD" >/dev/null
|
||||
runuser -u lightdm -- env HOME=/var/lib/lightdm \
|
||||
XDG_CONFIG_HOME=/var/lib/lightdm/.config \
|
||||
XDG_RUNTIME_DIR="/run/user/${lightdm_uid}" \
|
||||
/usr/share/rustdesk/rustdesk --option verification-method use-permanent-password >/dev/null
|
||||
fi
|
||||
systemctl restart rustdesk
|
||||
systemctl is-active --quiet rustdesk || fail 'The RustDesk service did not restart after setting its permanent password.'
|
||||
RUSTDESK_ID=$(rustdesk --get-id 2>/dev/null | tail -n 1 | tr -d '[:space:]')
|
||||
[[ $RUSTDESK_ID =~ ^[0-9]+$ ]] || fail "RustDesk returned an invalid device ID: $RUSTDESK_ID"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user