xlixiaohui 關注git
0.3 2018.03.26 10:09* 字數 861 閱讀 3293評論 4喜歡 4github
歡迎訪問個人我的博客:https://xiaohuilee.github.io/
主要的步驟是有兩步的:網絡
和以前的另外一篇操做文檔VNC Viewer輕鬆鏈接遠程CentOS6.8桌面不一樣,新的CentOS7有許多地方配置發生了變更,因此在這裏從新說明一下。session
1. 安裝Tigervnc-serversocket
Tigervnc-server is a program which executes an Xvnc server and starts parallel sessions of Gnome or other Desktop Environment on the VNC desktop.tcp
同個用戶能夠經過多個客戶端使用VNC會話。在CentOS7上安裝Tigervnc-server請打開終端,使用root用戶權限安裝:ide
sudo yum -y install tigervnc-server
2. 安裝完畢後,切換到你想使用Tigervnc-server的用戶,而後使用下列命令對VNC設置密碼,須要注意的是密碼長度必須爲6位以上:ui
su - your_user vncpasswd
系統提示:加密
[aukuno@localhost ~]$ vncpasswd Password: Verify: Would you like to enter a view-only password (y/n)? n A view-only password is not used
3. 接下來,在系統配置文件路徑下爲你的用戶添加一個VNC服務配置文件(daemon configuration file)。須要注意的是拷貝至系統路徑須要root權限。
加入當前用戶不具備root權限,請切換到root用戶(su - root
)或者使用如下命令:spa
sudo cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
4. 下一步,編輯從系統路徑(/etc/systemd/system/)拷貝過來的VNC的模板配置文件。將其中的用戶名改成你的用戶名。
(注意) 在 @後面的數字1表示的是顯示界面的序列號,對應的端口是port 5900+序列號。對於每個啓動的vncserver服務,端口號5900會自增1。
sudo vi /etc/systemd/system/vncserver@\:1.service
添加下列行到vncserver@:1.service.
[Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=forking ExecStartPre=/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。
sudo systemctl daemon-reload sudo systemctl start vncserver@:1 sudo systemctl status vncserver@:1 sudo systemctl enable vncserver@:1
Start VNC Service
6. 咱們能夠查看VNC server佔用的端口號,使用命令ss
——CentOS 7下用來顯示網絡sockets 佔用的命令。由於咱們剛剛打開了一個顯示會話,因此目前打開的端口應該是5901/TCP.
一樣的,使用ss
命令須要root權限。假如不一樣用戶登陸到了本機,對應的端口號就應該是5902,接下來應該是5903 等等,端口6000+是用於X應用鏈接到VNC server的.
ss -tulpn| grep vnc
Verify VNC Listening Ports
7. 爲了從外界訪問到CentOs,你還須要確保VNC server對應的端口能夠經過防火牆
目前咱們只打開了一個端口5901,咱們使用如下命令將5901添加到防火牆規則。
sudo firewall-cmd --add-port=5901/tcp sudo firewall-cmd --add-port=5901/tcp --permanent
8. 鏈接
Being a platform independent protocol, remote Graphical User Interface VNCconnections 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提醒鏈接沒有加密,點擊繼續便可。
VNC Viewer Client
VNC Viewer Client Connection
9. 接下來會彈出密碼確認窗口,輸入在第二點中設置的密碼,敲擊ok
便可鏈接到CentOs7
VNC Server User Password
VNC Remote CentOS Desktop
(注意)第一次鏈接可能出現顯示分辨率失常的狀況,斷開從新鏈接以及進入桌面後調整Display的分辨率可使其顯示正常。
小禮物走一走,來簡書關注我
讚揚支持