Virtual Network Computing(VNC)是基於Remote Framebuffer (RFB)協議(RFC6143)的圖形化桌面共享系統,可通過網路,控制遠程主機的桌面。
本文記錄在CentOS7.x中安裝、配置VNC Server(tigervnc),通過VNC連接遠程主機的圖形化桌面,並通過創建SSH Tunnel實現加密通信。
Introduction
VNC
Virtual Network Computing (VNC)的RFC編號是7869。
In computing,
Virtual Network Computing
(VNC) is a graphical desktop sharing system that uses the Remote Frame Buffer protocol (RFB) to remotely control another computer. It transmits the keyboard and mouse events from one computer to another, relaying the graphical screen updates back in the other direction, over a network. – https://en.wikipedia.org/wiki/Virtual_Network_Computing
TigerVNC
官方介紹
TigerVNC
is a high-performance, platform-neutral implementation of VNC (Virtual Network Computing), a client/server application that allows users to launch and interact with graphical applications on remote machines. TigerVNC provides the levels of performance necessary to run 3D and video applications, and it attempts to maintain a common look and feel and re-use components, where possible, across the various platforms that it supports. TigerVNC also provides extensions for advanced authentication methods and TLS encryption. – http://tigervnc.org/
RedHat官方文檔介紹
TigerVNC
(Tiger Virtual Network Computing) is a system for graphical desktop sharing which allows you to remotely control other computers.
TigerVNC
works on the client-server principle: a server shares its output (vncserver) and a client (vncviewer) connects to the server. – https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/ch-TigerVNC.html
TigerVNC
採用server/client架構,在server端安裝tigervnc-server
,在client端安裝tightvnc
或其它vncviewer。
Preparation
本文所有操作在DigitalOcean的VPS中進行,默認是root
用戶,為方便使用普通用戶賬戶登錄的用戶,在相關命令前添加sudo
指令。
VPS相關信息如下
item | detail |
---|---|
OS | CentOS Linux release 7.3.1611 (Core) |
Kernel | 3.10.0-514.2.2.el7.x86_64 |
IP | 192.241.240.132 |
通過SSH連接該主機,命令如下
|
|
使用VNC是為了連接圖形化桌面,故需在VPS中安裝圖形化卓名,此處選擇GNOME Desktop
。執行如下命令進行安裝
|
|
VNC軟件選擇tigervnc,安裝、配置過程參考RedHat官方文檔 CHAPTER 13. TIGERVNC。
TigerVNC Server
Installing
安裝tigervnc
,可通過如下命令查看相關安裝包
|
|
此處只安裝tigervnc-server
,為演示方便添加普通用戶tigervnc
,display_number 設置為1
。
執行如下命令安裝tigervnc-server
|
|
執行如下命令創建普通用戶tigervnc
|
|
Attention
Unlike in previous Red Hat Enterprise Linux distributions,
TigerVNC
in Red Hat Enterprise Linux 7 uses thesystemd
system management daemon for its configuration. The /etc/sysconfig/vncserver configuration file has been replaced by /etc/systemd/system/[email protected]. – https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/ch-TigerVNC.html
查看文件
|
|
其內容如下
|
|
註釋部分敘述了配置過程及通過SSH端口轉發實現加密通信。
重要:在複製文件/etc/systemd/system/[email protected]
時,涉及到 display_number,該參數可指定具體的數值,如1
、2
、3
等。VNC Server默認端口是5900
,如果指定了 display_number,則VNC Server最終的監聽端口號為5900 + display_number
。比如:指定 display_number 為1,則最終的監聽端口號為5901
;指定 display_number 為2,則最終的監聽端口號為5902
,依次類推。監聽端口可通過如下命令查看
|
|
The default port of VNC server is 5900. To reach the port through which a remote desktop will be accessible, sum the default port and the user’s assigned display number. For example, for the second display: 2 + 5900 = 5902. – https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sec-vnc-viewer.html
此處指定 display_number 為1
。
Configuring
執行如下命令進行配置
|
|
查看端口
|
|
VNC Viewer
Installing
對於client端而言,只需安裝vncviewer即可,可選擇的軟件有tigervnc
、xtightvncviewer
、xvnc4viewer
等,也可選擇RealVnc,或GNOME Desktop中的vinagre
(Applications–>Utilities–>Remote Desktop Viewer)。
|
|
Connecting Test
vncviewer
命令格式如下
|
|
執行
|
|
操作截圖
Real vncviewer
在如下頁面下載RealVNC Viewer
|
|
此處下載
|
|
解壓至目錄/tmp
中,執行
|
|
操作截圖
vinagre
如何打開Applications
–>Utilities
–>Remote Desktop Viewer
操作截圖
SSH Localhost Forwarding
設置SSH本地端口轉發,參考RedHat官方文檔10.4. MORE THAN A SECURE SHELL中相關章節,命令格式如下
|
|
此處將其改寫為
|
|
要求輸入用戶tigervnc
的密碼。
將目標主機的5901
端口通過SSH Tunnel轉發到本地的9876
端口。
執行
|
|
正常打開遠程主機桌面。
此時執行
|
|
仍能打開目標主機桌面。
Only Allow From LocalHost
出於安全考慮,設置VNC Server只允許VPS本地localhost
訪問。創建SSH Tunnel後,就能直接訪問
修改文件
|
|
修改後,直接連接報錯
|
|
通過SSH Tunnel可正常連接
|
|
操作截圖
References
- Install & Configure VNC Server in CentOS 7 and RHEL 7
- How To Install and Configure VNC Remote Access for the GNOME Desktop on CentOS 7
Change Logs
- 2017.01.02 17:54 Mon Asia/Shanghai
- 初稿完成
- 2018-08-01 22:46 Wed Asia/Shanghai
- 勘誤,排版,遷移到新Blog