Make Mac Mini an RDP Server
Make Mac Mini an RDP Server | 使用 RDP 遠程連接 Mac Mini
⚠️ THIS POST HAS A "靈車漂移" TAG, AND DOES NOT GUARANTEE STABILITY.
⚠️ 呢篇文章帶有「靈車漂移」之標籤,並且不保證穩定性。
0. Background & Motivation | 背景及動機
Recently Rain is using a combination of "separated" NAS and remote desktop, that is, an Intel NUC with a mounted external hard disk. It is worth attention that I want to have a user-friendly command line environment as well as a beautiful graphic user interface (GUI), so I installed a macOS Big Sur 11.9 on NUC, also called "Hacintosh". I will called it "Nucintosh" because it is installed on a NUC hardware.
呢排 Rain 用緊一個「散裝」NAS 及遠程桌面結合物,即係一台 Intel NUC,並掛載有一個外置硬碟。值得注意嘅係 Rain 想要一個用戶友好嘅命令行終端環境,又同時想要一個優雅美麗嘅圖形用戶介面,所以選擇喺 NUC 之上安裝 macOS Big Sur 11.9 系統,即係話安裝一個「黑蘋果」。因為佢運行於 NUC 硬件之上,所以喺下文中將稱呼佢為「Nucintosh」。
It is generally acknowledge that macOS use ARD to connect from remote, and it does not support the RDP protocol form Microsoft. Rain wants to make Nucintosh be connected via RDP, so that maybe I can adjust the resolution settings from remote client. (not sure)
一般來講,macOS 係用 ARD 喺遠端連線,而且佢唔支援微軟嘅 RDP 協定。 Rain 想令到 Nucintosh 透過 RDP 連接,咁我可能可以喺遠端客戶端調整解像度嘅設定。(唔確定)
The method is to build an RDP server on macOS and make it run rdp services, and there is an open source solution called xrdp (GitHub repo) but however it does not support macOS officially.
此方法係專門構建一個 RDP 伺服器於 macOS 系統之上,令到佢運行 RDP 服務。而且有一個叫做「xrdp」嘅開源嘅解決方案,但係佢冇官方嘅 macOS 支援。
According to some discussions, there is a way to make Macs run xrdp and get remote connected.
根據一啲討論,有一種方法可以令到 Mac 電腦運行 xrdp 並使得可以被遠程連接控制。
1. Compile XRDP | 編譯 XRDP
I choose xrdp 0.9.19 version for this task. Someone said this version runs well on macOS Monterey. My Nucintosh runs a macOS Big Sur system, which is earlier than macOS Monterey, so it has a large probability to work with xrdp 0.9.19 as well. Let us have a try.
我選擇 xrdp 0.9.19 呢個版本。有啲人話呢個版本喺 macOS Monterey 上面運行良好。我嘅 Nucintosh 搭載一個 macOS Big Sur 系統,相比於 Monterey 早一個大版本,因此有相當大可能性令到 xrdp 0.9.19 運行良好。讓我哋試一試。
1.1. Prepare dependencies | 準備依賴
We need these following dependencies:
我哋需要下面呢啲依賴庫:
- Xcode commandline tools
- Homebrew
- OpenSSL
- Automake and Autoconfig
- Libtool
- pkgconfig
- nasm
- XQuartz and its libs
If the machine do not have Homebrew installed, it is required to install one.
如果機器上面冇安裝 Homebrew,咁應該安裝一個先。
First, get Xcode command line tools ready.
首先,準備好 Xcode 命令行工具(Xcode Commandline Tools)。
xcode-select --install
Then install Homebrew.
然後安裝 Homebrew。
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
It is also okay to have the macOS has MacPorts installed, like my Nucintosh, but it is also highly recommend to install Homebrew in this case. Some dependencies seem can only be installed from Homebrew, like XQuartz components.
如果 macOS 已經安裝咗 MacPorts 都冇問題。好似 Nucintosh 一樣既有 MacPorts 又有 Homebrew。但係仍然非常推薦安裝 Homebrew,因為我哋後面需要用到。一啲依賴庫只能夠從 Homebrew 嗰度安裝,例如 XQuartz 嘅組件。
Install openssh.
安裝 openssh。
brew install openssh
Install automake and autoconfig.
安裝 automake 同埋 autoconfig。
brew install automake
Install libtool.
安裝 libtool。
brew install libtool
Install pkgconfig.
安裝 pkgconfig。
brew install pkgconfig
Install nasm.
安裝 nasm。
brew install nasm
Install XQuartz and its related libraries.
安裝 XQuartz 及其相關嘅庫。
brew install xquartz
brew install libx11
brew install libxfixes
brew install libxrandr
Make sure all the dependencies above are installed.
確保所有嘅依賴都已經安裝好。
1.2. Get XRDP source code | 獲取 XRDP 嘅源碼
All the operations are completed via terminal and CLI, so the only thing now I need to do is to download xrdp 0.9.19 source code archive via command line. I use wget to do this.
所有嘅操作都係喺終端嘅命令行介面完成嘅,因此依家需要通過命令行工具來下載 xrdp 0.9.19 源代碼包。使用 wget 即可做到。
wget "https://github.com/neutrinolabs/xrdp/releases/download/v0.9.19/xrdp-0.9.19.tar.gz"
If the system do not have a wget tool installed, we can install from Homebrew easily. (if neccessary)
如果系統上面冇安裝 wget 工具,可以使用 Homebrew 來安裝。(如果必要嘅話)
brew install wget
Move this tar file to a coding place, for example, I put it in ~/Coding directory.
將呢個 tar 歸檔文件移動去一個編寫代碼嘅常用位置,例如我將佢放喺 ~/Coding 嘅目錄下面。
mv xrdp-0.9.19.tar.gz ~/Coding
Use tar tool to extract the package.
使用 tar 工具解壓源碼包。
tar -xvf xrdp-0.9.19.tar.gz
Then cd into the directory.
然後 cd 入嗰個目錄。
cd xrdp-0.9.19
1.3. Compile and build | 編譯並構建
These steps are for x86_64 Macs.
呢啲步驟適用於 x86_64 架構嘅 Mac 電腦。
Start.
開始配置。
./bootstrap
Configure the project. If the system does not have pkgconfig installed, it will throw an error out here.
配置項目。如果個系統冇安裝有 pkgconfig,佢會丟出一個報錯喺度。
./configure PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
Make and build.
構建。
make
Install xrdp.
安裝 xrdp。
sudo make install
The xrdp will be installed at /usr/local/sbin/xrdp by default.
xrdp 呢個程序將會默認被安裝喺 /usr/local/sbin/xrdp 嘅位置。
2. Settings for XRDP | XRDP 設定
Make sure xrdp is installed on macOS.
確保 xrdp 已經安裝喺 macOS 之中。
which xrdp
If the output is /usr/local/sbin/xrdp, then xrdp is installed correctly. Generally, if no changes were made in source code before installation, the configuration file xrdp.ini will be stored at /etc/rxdp. Use vim or other text editor to open it, with root privilige.
如果輸出係 /usr/本地/sbin/xrdp,咁 xrdp 就安裝得正確。一般嚟講,如果喺安裝之前冇對源碼作出任何變更,配置檔案 xrdp.ini 就會儲存喺 /etc/rxdp。使用 root 權限,用 vim 或者其他編輯器打開佢。
sudo vim /etc/xrdp/xrdp.ini
We need to change some of the configurations to make xrdp run correctly on macOS.
我哋需要修改一啲配置項來令到 xrdp 喺 macOS 上面正確運行。
Find [vnc-any] line. The following lines are below:
搵到 [vnc-any] 呢行。呢行下面幾行嘅內容:
[vnc-any]
name=vnc-any
lib=libvnc.so
ip=ask
port=5900
username=ask
password=ask
#pamusername=asksame
#pampassword=asksame
#pamsessionmng=127.0.0.1
#delay_ms=2000
We need to make some changes, like below.
修改一啲部分,如下。
[vnc-any]
name=vnc-any
lib=libvnc.dylib
ip=127.0.0.1
port=5900
username=ask
password=ask
#pamusername=asksame
#pampassword=asksame
#pamsessionmng=127.0.0.1
#delay_ms=2000
lib file should be libvnc.dylib on macOS instead of libvnc.so on Linux. ip should be set to 127.0.0.1 by default.
喺 macOS 上面,lib 文件應該為 libvnc.dylib,而唔係 Linux 上嘅 libvnc.so。設定默認嘅 ip 為 127.0.0.1。
There are other session types, just comment them if not used, or they may cause some remote desktop client cannot connect successfully. Some clients may not display the xrdp portal correctly and lead to a crash.
佢仲有其他嘅 session 種類,如果唔使用嘅話刪除或者註釋咗佢即可。不然嘅話佢哋可能導致喺某些遠程桌面客戶端上面嘅連接失敗。一啲客戶端可能顯示唔到 xrdp 嘅 portal 介面,並導致崩潰。
After editting the configuration file, save changes and exit vim.
編輯完配置文件之後,保存並且退出 vim。
3. Start XRDP services
Use root to run xrdp.
sudo /usr/local/sbin/xrdp
sudo /usr/local/sbin/xrdp-sesman
Or, if the directory is in the PATH,
或者,如果個目錄喺 PATH 之中嘅話,
sudo xrdp
sudo xrdp-sesman
4. Connect from another machine | 從另外機器上連接
I use Remote Desktop Manager to connect Nucintosh remotely. After I added a RDP session, it connected successfully. xrdp works. However, I soon found that I still cannot adjust the resolution. It is a limitation from macOS, not from ARD.
使用 Remote Desktop Manager 遠程連接 NUC。添加一個 RDP session 之後,佢成功連接。xrdp 工作正常。但係我好快發現佢仍然唔可以係客戶端調整分辨率。呢個係系統嘅限制,而唔係 ARD 嘅限制。
5. Conclusion | 總結
xrdp can work on macOS, making it possible to use RDP (including the built-in Remote Desktop on Windows) connect to Mac. RDP cannot realize the "dynamic resolution" on macOS and some Linux distros. These limitations are from the operating systems, not from remote desktop protocols.
xrdp 可以喺 macOS 上面運行,可以令到 macOS 使用 RDP 來被遠程連接。RDP 喺 macOS 及一啲 Linux 發行版本上面唔可以實現「動態分辨率」功能。呢啲限制係由於系統,並非遠程桌面協議控制。