作者: Jack
場景
機房服務器安裝了Ubuntu Desktop,但沒外接顯示器,而有時我們需要遠程至Ubuntu Desktop的GUI桌面。這里梳理出一個方案,主要有以下幾點:
- 使用Ubuntu內置的vino VNC提供遠程桌面訪問。
- 配置Ubuntu在服務器無外接顯示器時啟動桌面GUI。
- 配置Ubuntu自動登錄桌面會話,以解決vino的一個缺陷。
環(huán)境
- Ubuntu 16.04 & 18.04。
配置VNC服務
vino是Ubuntu內置的桌面共享VNC服務,也是最簡單穩(wěn)定的,雖然功能不多。
安裝:
sudo apt install vino
配置:打開如下圖的幾個選項。

配置
啟動無顯示器Ubuntu的桌面GUI
默認情況下,服務器無外接顯示器的話,Ubuntu不會啟動桌面GUI。
這里使用虛擬顯示器(dummy monitor)方法:
安裝dummy monitor:
sudo apt install xserver-xorg-video-dummy
編輯文件:
sudo vi /usr/share/X11/xorg.conf.d/xorg.conf
寫入如下內容(這里是配置為1024x768的分辨率)并重啟:
Section "Monitor"
Identifier "Monitor0"
HorizSync 28.0-80.0
VertRefresh 48.0-75.0
# https://arachnoid.com/modelines/
# 1024x768 @ 60.00 Hz (GTF) hsync: 47.70 kHz; pclk: 64.11 MHz
Modeline "1024x768_60.00" 64.11 1024 1080 1184 1344 768 769 772 795 -HSync +Vsync
EndSection
Section "Device"
Identifier "Card0"
Driver "dummy"
VideoRam 256000
EndSection
Section "Screen"
DefaultDepth 24
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
SubSection "Display"
Depth 24
Modes "1024x768_60.00"
EndSubSection
EndSection
自動登錄桌面會話
溫馨提示:下面的自動登錄配置是不安全的做法。
vino VNC服務有個問題,它是在Ubuntu桌面會話啟動后才啟動的(Log out登出桌面也即關閉了此服務)。vino VNC服務不啟動的話,就無法VNC遠程Ubuntu。
因此配置Ubuntu自動登錄桌面會話來規(guī)避之。方法如下:
編輯文件:
sudo vi /etc/lightdm/lightdm.conf
追加如下內容并重啟:
#追加
[SeatDefaults]
autologin-user=<用戶名>
autologin-user-timeout=0
user-session=ubuntu
FAQ
桌面登錄后提示顯示器分辨率不匹配
類似如下的提示:
none of the selected modes were compatible with the possible modes:
Trying modes for CRTC 63 CRTC 63:
trying mode 1024x768@60Hz with output at 1680x1050@60Hz (pass 0)
CRTC 63: trying mode 800x600@60Hz with output at 1680x1050@60Hz (pass 0)
CRTC 63: trying mode 800x600@56Hz with output at 1680x1050@60Hz (pass 0)
解決方法:刪除舊的配置文件并重啟(保險起見,重命名他)。
mv ~/.config/monitors.xml ~/.config/monitors.xml.backup
xserver-xorg-video-dummy安裝失敗
安裝時可能有如下錯誤:
$ sudo apt install xserver-xorg-video-dummy
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
xserver-xorg-video-dummy : Depends: xorg-video-abi-20
Depends: xserver-xorg-core (>= 2:1.17.99.902)
E: Unable to correct problems, you have held broken packages.
解決方法:安裝跟Ubuntu版本對應的包。
查看是否是hwe版本的Ubuntu內核。如有出現(xiàn)如下的過濾結果,說明是hwe內核。
$ dpkg -l|grep linux-headers|grep hwe
ii linux-headers-generic-hwe-18.04 4.18.0.22.72 amd64 Generic Linux kernel headers
搜索xserver-xorg-video-dummy包:
$ sudo apt search xserver-xorg-video-dummy
Sorting... Done
Full Text Search... Done
xserver-xorg-video-dummy/bionic 1:0.3.8-1build1 amd64
X.Org X server -- dummy display driver
xserver-xorg-video-dummy-hwe-16.04/bionic 3:14.1 amd64
Transitional package for xserver-xorg-video-dummy-hwe-16.04
xserver-xorg-video-dummy-hwe-18.04/bionic-updates 1:0.3.8-1build3~18.04.1 amd64
X.Org X server -- dummy display driver
安裝對應的包:比如系統(tǒng)是18.04,hwe內核,則安裝如下包:
sudo apt install xserver-xorg-video-dummy-hwe-18.04