這是本文件的舊版!
Ubuntu 安裝遠端桌面(XRDP + XFCE)
- 因為建立一個 VM 來測試 Ubuntu Desktop 的功能, 想看看有沒有比 VNC 效能好一點的服務, 後來找到 xrdp 可以測試看看
- 安裝環境 : Ubuntu-24.04 Server 版
安裝方式
Step 1:安裝桌面環境與 xrdp
sudo apt update && sudo apt upgrade -y # 安裝輕量桌面 XFCE sudo apt install -y xfce4 xfce4-goodies # 安裝 xrdp 與必要套件 sudo apt install -y xrdp dbus-x11
- dbus-x11 是關鍵套件,沒有它 xfce4 無法建立 dbus session,會導致登入後立刻跳出。
Step 2:停用 LightDM(Server 版關鍵步驟)與關閉 Wayland(24.04 關鍵修正)
- 安裝 xfce4 時會自動安裝 LightDM,它會與 xrdp 的 session 產生衝突,必須停用
sudo systemctl disable lightdm sudo systemctl stop lightdm
- 停用後主機本機螢幕將無桌面,但 RDP 遠端連線完全正常,Server 環境這是正確做法。
- 停用 Wayland,強制使用 X11
sudo sed -i 's/#WaylandEnable=false/WaylandEnable=false/' /etc/gdm3/custom.conf
如果安裝無桌面版 Exp. Server 不會有 GDM3, 就不需要關閉 Wayland
執行就會出現
$ sudo sed -i 's/#WaylandEnable=false/WaylandEnable=false/' /etc/gdm3/custom.conf sed: can't read /etc/gdm3/custom.conf: No such file or directory
Step 3:設定 xrdp 使用 XFCE
- 為目前使用者設定 xfce4 為預設 session
echo xfce4-session > ~/.xsession chmod +x ~/.xsession
- 直接替換 startwm.sh,讓 xrdp 乾淨地啟動 xfce4,避免繼承殘留的舊 dbus 環境:
# 先備份 sudo cp /etc/xrdp/startwm.sh /etc/xrdp/startwm.sh.bak # 寫入新內容 sudo bash -c 'cat > /etc/xrdp/startwm.sh << EOF #!/bin/sh export XDG_SESSION_TYPE=x11 export XDG_SESSION_DESKTOP=xfce export XDG_CURRENT_DESKTOP=XFCE unset DBUS_SESSION_BUS_ADDRESS unset XDG_RUNTIME_DIR if test -r /etc/profile; then . /etc/profile fi if test -r ~/.profile; then . ~/.profile fi exec startxfce4 EOF' sudo chmod +x /etc/xrdp/startwm.sh
Step 4:修正 polkit 認證問題(解決黑畫面 / 認證彈窗)
- 建立 polkit 規則,避免連線後跳出認證視窗或黑畫面
sudo mkdir -p /etc/polkit-1/localauthority/50-local.d/ sudo bash -c 'cat > /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla << EOF [Allow Colord all Users] Identity=unix-user:* Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile ResultAny=yes ResultInactive=yes ResultActive=yes EOF'
Step 5:加入 ssl-cert 群組(解決 TLS 憑證問題)
sudo adduser xrdp ssl-cert
Step 6:設定開機自動啟動(解決重開機問題)
- 啟用並設定開機自動啟動
sudo systemctl enable xrdp sudo systemctl enable xrdp-sesman
- 啟動服務
sudo systemctl restart xrdp - 確認服務正常運行
sudo systemctl status xrdp
Step 7:主機防火牆設定
- 開放 RDP port(若有使用 ufw)
sudo ufw allow 3389/tcp sudo ufw reload sudo ufw status
Step 8:驗證
- 驗證開機自動啟動
# 重開機後確認 xrdp 是否自動啟動 sudo reboot # 重開機後 SSH 進去確認 sudo systemctl is-enabled xrdp # 應顯示 "enabled" sudo systemctl is-active xrdp # 應顯示 "active" # 確認 LightDM 已停用 sudo systemctl is-enabled lightdm # 應顯示 disabled # 確認 port 3389 正在監聽 sudo ss -tlnp | grep 3389
FAQ
1. 常見出現 Xorg 輸入帳號密碼後, 登入畫面一直卡在藍畫面或跳開的問題
- 登入後立刻跳出缺少 : dbus-x11 或 startwm.sh 設定錯誤 → Step 1 + Step 3
- 藍畫面/黑畫面 : LightDM 與 xrdp 衝突 → Step 2
- 跳出認證視窗 : polkit 規則缺失 → Step 4
- 重開機後無法連線 : 未設定 enable → Step 6
- 出現 /etc/gdm3/custom.conf 不存在 訊息 : Server 版無 GDM3 → 執行 Step 2 停用 LightDM
2. 現在來安裝注音輸入法(IBus + 新酷音)
- 在 RDP 桌面內開啟 Terminal,執行:
# 安裝 IBus 與注音輸入法(新酷音 chewing) sudo apt install -y ibus ibus-chewing # 設定 IBus 為預設輸入法框架 im-config -n ibus # 將 IBus 加入啟動環境 echo 'export GTK_IM_MODULE=ibus export XMODIFIERS=@im=ibus export QT_IM_MODULE=ibus ibus-daemon -drx' >> ~/.profile 然後啟動 IBus 設定: ibus-daemon -drx & ibus-setup 在 IBus 設定視窗中: 點 Input Method 分頁 點 Add → 搜尋 Chinese → 選 Chewing(新酷音) 確認後關閉
如果 Input Method 找不到 Chonese
可以重新啟動 ibus 後, 再次進入 ibus-setup
ibus restart ibus-setup
- 最後登出再重新 RDP 連線即可使用
- 切換輸入法快捷鍵預設為 CapsLock 可以透過設定改成 Shift。