- CentOS7安裝tigervnc-server並啓用
yum install tigervnc-server -y
- 查看
/lib/systemd/system/[email protected]
cat /lib/systemd/system/[email protected]
- 裏面詳細描述瞭如何使用。
# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/[email protected]
# 2. Replace <USER> with the actual user name and edit vncserver
# parameters appropriately
# (ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
# PIDFile=/home/<USER>/.vnc/%H%i.pid)
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.
-
共分爲四個步驟:
- 將
/etc/systemd/system/[email protected]
文件拷貝爲/etc/systemd/system/vncserver@:<display>.service
這裏<display>
是表示第幾個顯示屏,可以設置爲1。
cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service
- 將
<USER>
標識的字段,替換爲用戶名,例如root
,並正確修改vnc啓動參數(ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i PIDFile=/home/<USER>/.vnc/%H%i.pid)"
vi /etc/systemd/system/vncserver@:1.service
- 運行
systemctl daemon-reload
systemctl daemon-reload
- 運行
systemctl enable vncserver@:<display>.service
,這裏<display>
是表示第幾個顯示屏。
systemctl enable vncserver@:1.service
另外,它告訴我們不要在不受信任的網絡上使用如上配置進行vnc訪問。如果有需求,可以進行更多的配置,使用ssh等進行保護。
- 將
-
修改root訪問vnc的密碼
vncpasswd root
- 啓動vncserver(注意,啓動前最好關閉防火牆和selinux,否則可能會被策略阻擋導致無法連接上)
systemctl start vncserver@:1
- 關閉防火牆,selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vi /etc/selinux/config
修改enforcing
爲disabled
- 啓動後可以通過
systemctl status -l vncserver@:1
來查看vncserver服務的狀態。
- 客戶端下載
vnc-viewer
,realvnc
等軟件,進行訪問,通過ip:1
訪問vnc服務端。