VNC Viewer輕鬆連接遠程CentOS7桌面

主要的步驟是有兩步的:

Step 1: 在CentOs7上安裝Tigervnc-server

Step 2: 使用VNC Client連接到CentOS桌面

和之前的另一篇操作文檔VNC Viewer輕鬆連接遠程CentOS6.8桌面不同,新的CentOS7有許多地方配置發生了變動,所以在這裡重新說明一下。

Step 1: 在CentOs7上安裝Tigervnc-server

1. 安裝Tigervnc-server

Tigervnc-server is a program which executes an Xvnc server and starts parallel sessions of Gnome or other Desktop Environment on the VNC desktop.

同個用戶可以通過多個客戶端使用VNC會話。在CentOS7上安裝Tigervnc-server請打開終端,使用root用戶許可權安裝:

sudo yum -y install tigervnc-server

2. 安裝完畢後,切換到你想使用Tigervnc-server的用戶,然後使用下列命令對VNC設置密碼,需要注意的是密碼長度必須為6位以上:

su - your_uservncpasswd

3. 接下來,在系統配置文件路徑下為你的用戶添加一個VNC服務配置文件(daemon configuration file)。需要注意的是拷貝至系統路徑需要root許可權。

加入當前用戶不具有root許可權,請切換到root用戶(su - root)或者使用以下命令:

sudo cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

4. 下一步,編輯從系統路徑(/etc/systemd/system/)拷貝過來的VNC的模板配置文件。將其中的用戶名改為你的用戶名。

(注意) 在 @後面的數字1表示的是顯示界面的序列號,對應的埠是port 5900+序列號。對於每一個啟動的vncserver服務,埠號5900會自增1

vi /etc/systemd/system/vncserver@:1.service

添加下列行到vncserver@:1.service.

[Unit]Description=Remote desktop service (VNC)After=syslog.target network.target[Service]Type=forkingExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || :#my_user是你想使用VNC Server的用戶名ExecStart=/sbin/runuser -l my_user -c "/usr/bin/vncserver %i -geometry 1280x1024"#my_user是你想使用VNC Server的用戶名PIDFile=/home/my_user/.vnc/%H%i.pid ExecStop=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || :[Install]WantedBy=multi-user.target

5. 添加完畢後,重新運行系統systemd的初始化程序以便使新的配置文件生效,然後重啟TigerVNC server

與此同時,檢查VNC service的狀態同時啟用VNC daemon system-wide。

systemctl daemon-reloadsystemctl start vncserver@:1systemctl status vncserver@:1systemctl enable vncserver@:1

6. 我們可以查看VNC server佔用的埠號,使用命令ss——CentOS 7下用來顯示網路sockets 佔用的命令。因為我們剛剛打開了一個顯示會話,所以目前打開的埠應該是5901/TCP.

同樣的,使用ss命令需要root許可權。假如不同用戶登錄到了本機,對應的埠號就應該是5902,接下來應該是5903 等等,埠6000+是用於X應用連接到VNC server的.

ss -tulpn| grep vnc

7. 為了從外界訪問到CentOs,你還需要確保VNC server對應的埠可以通過防火牆

目前我們只打開了一個埠5901,我們使用以下命令將5901添加到防火牆規則。

firewall-cmd --add-port=5901/tcpfirewall-cmd --add-port=5901/tcp --permanent

Step 2: 使用VNC Client連接到CentOS桌面

8. 連接

Being a platform independent protocol, remote Graphical User Interface VNC connections can be performed from almost any operating system with a GUI and a specialized VNC client.

A popular VNC client used in Microsoft based operating systems, fully compatible with Linux TigerVNC server, is the RealVNC VNC Viewer.

打開VNC Viewer,在VNC Server一欄輸入CentOs的ip地址,需要加上對應的埠號(192.168.1.23:5901),敲擊回車。

當連接建立以後,會有warning提醒連接沒有加密,點擊繼續即可。

9. 接下來會彈出密碼確認窗口,輸入在第二點中設置的密碼,敲擊ok即可連接到CentOs7

(注意)第一次連接可能出現顯示解析度失常的情況,斷開重新連接以及進入桌面後調整Display的解析度可以使其顯示正常。


推薦閱讀:

TAG:Linux | 遠程桌面mstsc |