顯示頁面舊版反向連結Fold/unfold all回到頁頂 本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。 ====== Ubuntu 安裝遠端桌面(XRDP + XFCE) ====== * 因為建立一個 VM 來測試 Ubuntu Server 的遠端桌面(XWindow)功能, 想看看有沒有比 VNC 效能好一點的服務, 後來找到 xrdp 可以測試看看 * 安裝環境 : Ubuntu-24.04 Server 版 ===== 安裝方式 ===== ==== Step 1:安裝桌面環境與 xrdp ==== * <cli> sudo apt update && sudo apt upgrade -y # 安裝輕量桌面 XFCE sudo apt install -y xfce4 xfce4-goodies # 安裝 xrdp 與必要套件 sudo apt install -y xrdp dbus-x11 </cli> * dbus-x11 是關鍵套件,沒有它 xfce4 無法建立 dbus session,會導致登入後立刻跳出。 ==== Step 2:停用 LightDM(Server 版關鍵步驟)與關閉 Wayland(24.04 關鍵修正)==== * 安裝 xfce4 時會自動安裝 LightDM,它會與 xrdp 的 session 產生衝突,必須停用<cli> sudo systemctl disable lightdm sudo systemctl stop lightdm </cli> * 停用後主機本機螢幕將無桌面,但 RDP 遠端連線完全正常,Server 環境這是正確做法。 * 停用 Wayland,強制使用 X11<cli> sudo sed -i 's/#WaylandEnable=false/WaylandEnable=false/' /etc/gdm3/custom.conf </cli> <note> **如果安裝無桌面版 Exp. Server 不會有 GDM3, 就不需要關閉 Wayland** 執行就會出現<cli> $ 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 </cli> </note> ==== Step 3:設定 xrdp 使用 XFCE ==== * 為目前使用者設定 xfce4 為預設 session<cli> echo xfce4-session > ~/.xsession chmod +x ~/.xsession </cli> * 直接替換 startwm.sh,讓 xrdp 乾淨地啟動 xfce4,避免繼承殘留的舊 dbus 環境:<cli> # 先備份 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 </cli> ==== Step 4:修正 polkit 認證問題(解決黑畫面 / 認證彈窗)==== * 建立 polkit 規則,避免連線後跳出認證視窗或黑畫面<cli> 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' </cli> ==== Step 5:加入 ssl-cert 群組(解決 TLS 憑證問題)==== * <cli> sudo adduser xrdp ssl-cert </cli> ==== Step 6:設定開機自動啟動(解決重開機問題)==== * 啟用並設定開機自動啟動<cli> sudo systemctl enable xrdp sudo systemctl enable xrdp-sesman </cli> * 啟動服務<cli> sudo systemctl restart xrdp </cli> * 確認服務正常運行<cli> sudo systemctl status xrdp </cli> ==== Step 7:主機防火牆設定 ==== * 開放 RDP port(若有使用 ufw)<cli> sudo ufw allow 3389/tcp sudo ufw reload sudo ufw status </cli> ==== Step 8:驗證 ==== * 驗證開機自動啟動<cli> # 重開機後確認 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 </cli> ===== 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,執行:<cli> # 安裝 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(新酷音) 確認後關閉 </cli> <note> **如果 Input Method 找不到 Chonese** 可以重新啟動 ibus 後, 再次進入 ibus-setup <cli> ibus restart ibus-setup </cli> </note> * 最後登出再重新 RDP 連線即可使用 * 切換輸入法快捷鍵預設為 CapsLock 可以透過設定改成 Shift。 ===== 參考網址 ===== * http://honglung.pixnet.net/blog/post/167257893-windows-%E9%81%A0%E7%AB%AF%E6%A1%8C%E9%9D%A2%E9%80%A3%E7%B7%9A%E5%88%B0-ubuntu-16.04 * http://it.cpunews.net/1592/ * https://www.twblogs.net/a/5c38452dbd9eee35b21d8750 * https://superuser.com/questions/644804/disable-screensaver-screen-blank-via-command-line/644829 {{tag>xrdp 遠端桌面}} tech/ubuntu_xrdp.txt 上一次變更: 2026/03/23 12:29由 jonathan