Linux VM 上安裝桌面環境

Posted in :

想在遠端的Server上, 使用桌面的應用程式, 例如: java 的 IDE.

收集到的一些相關文章裡:

Microsoft 建議的指令:

sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install xfce4
sudo apt install xfce4-session

在 Ubuntu 安裝 xrdp

sudo apt-get -y install xrdp
sudo systemctl enable xrdp

在 Ubuntu 20 上,您必須提供憑證存取權給 xrdp 使用者:

sudo adduser xrdp ssl-cert

設定 xrdp 以使用 xfce 做為您的桌面環境,如下所示︰

echo xfce4-session >~/.xsession

重新啟動 xrdp 服務,讓變更生效︰

sudo service xrdp restart

然後,新增使用者:

sudo adduser your_new_username

Add User to Sudoers group

usermod -aG sudo your_new_username

在 Rocky linux 8 安裝 xrdp

sudo yum update
sudo yum groupinstall "Server with GUI"
sudo dnf install epel-release
sudo dnf install xrdp
sudo systemctl enable xrdp
sudo systemctl start xrdp
sudo firewall-cmd --permanent --add-port=3389/tcp
sudo firewall-cmd --reload
sudo reboot

附註: 如果有執行 sudo systemctl set-default graphical 會造成登入介面變成GUI。

在 Rocky linux 9 安裝 xrdp

sudo dnf update
sudo dnf install epel-release
sudo dnf install xrdp
sudo systemctl enable xrdp
sudo systemctl start xrdp
sudo firewall-cmd --permanent --add-port=3389/tcp
sudo firewall-cmd --reload
sudo reboot

說明: 在 Rocky linux 8 使用上一面的安裝步驟, 會造成無法登入帳號。


連線到伺服器

  • 如果您的系統是macOS,則可以從Mac App Store安裝Microsoft遠程桌面應用程式。
  • Linux用戶可以使用RDP客戶端,例如Remmina或Vinagre。
  • Windows 用戶,執行 mstsc.exe 應用程式。

疑難排解

很慘烈, 我已經刪掉 VM 很多次, 從 ubuntu, 也挑戰開機多次….

當你遇到登入超久, 然後顯示下列的錯誤訊息:

第一件事情就是, 登入伺服器看錯誤訊息:

tail -f /var/log/xrdp.log

或這個

tail -f /var/log/xrdp-sesman.log

或這個

tail -f /var/log/syslog

Ubuntu 18.04, Blank screen after login from Windows 10
https://github.com/neutrinolabs/xrdp/issues/1358

滿滿的 issuue:
https://github.com/neutrinolabs/xrdp/issues

某網友解答:
http://catch22cats.blogspot.com/2018/05/xrdp-blank-screen-with-ubuntu-1804.html

One cause of this is that xfce4 has added code that prevents a second session from opening. You will find that if your computer’s main screen is logged into xfce4 you may not be able to use it with xrdp.

To solve this “second session” problem and allow as many sessions as you need, edit /etc/xrdp/startwm.sh and add these lines before the lines that test and execute Xsession. The $HOME/.profile is not part of the solution, but is something that should be run before starting the session anyway.

unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR
. $HOME/.profile

下面, 是另一篇的解法, 一樣卡關, 已經從 ubuntu 22 降到 ubuntu 20, 還是登不進去. 呵呵.

要連進去遠端的ubuntu虛擬主機上, 執行下面指令, 通常會下載和安裝很久, 大約 5分鐘吧.

sudo apt install ubuntu-desktop-minimal -y

digitalocean 使用的完整版, 在 ubuntu 裡要快 1GB, To install Ubuntu Desktop on your Droplet, run the following command and follow the prompts:

sudo apt-get install ubuntu-desktop

Install the Xrdp package using the following command.

sudo apt install xrdp -y

Check the Xrdp status using the following command.

systemctl status xrdp

我執行畫面, 綠色字說, 執行中.

開 ufw 防火牆

sudo ufw allow 3389
sudo ufw reload
sudo ufw status

試了半天, 也有重開機, 也用了 sudo service ufw start , 服務就是 inactive, 算了, 沒防火牆也差.

因為都有更上層的rule 可以套用到虛擬主機上:
https://stackoverflow.max-everyday.com/2023/02/ip-cidr/


Add New User Account

在 ubuntu add user:

sudo adduser newuser

設定帳號密碼

sudo passwd newuser

檢查groups

groups newuser

ubuntu 加入為管理者:

sudo usermod -aG sudo newuser

rocky 加入為管理者:

sudo usermod -aG wheel newuser

或是:

sudo usermod -aG adm newuser
sudo usermod -aG systemd-journal newuser

切換目前的使用者帳號:

sudo su - newuser

心得

我測試了 ubuntu 18,20,22 都遇到「諸多」的問題,雖然有依照顯示的錯誤訊息去找解答,但我個人功能太弱,在目前這一家提供虛擬主機業者的Ubuntu環境下都無法成功,猜測有可能是他的 gold image 裡有相關的 driver 沒有正常被載入, 造成 xorg 的 remote desktop (xwindows) 無法被啟用。

針對這家虛擬主機業者的解法,是使用 cenOS 或 Rocky 就解決了。原本以為用戶數較多的 ubuntu 問題會較少,有可能是這個提供虛擬主機的 gold image 主要是用在高速計算領域,所以對 GUI 上的調校就較少。

附上成功進入 Rocky 並安裝 chrome 與 eclipse 的畫面:

當你第一次挑戰安裝遠端桌面, 還是建議先試看看 ubuntu 平台, 不行的話, 再來挑戰網路上討論度較低的 Rocky Linux.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *