CentOS7安装tigervnc-server并启用

  1. CentOS7安装tigervnc-server并启用
yum install tigervnc-server -y
  1. 查看/lib/systemd/system/[email protected]
cat /lib/systemd/system/[email protected]
  1. 里面详细描述了如何使用。
# 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.
  1. 共分为四个步骤:

    1. /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
    
    1. <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
    
    1. 运行systemctl daemon-reload
    systemctl daemon-reload
    
    1. 运行systemctl enable vncserver@:<display>.service,这里<display>是表示第几个显示屏。
    systemctl enable vncserver@:1.service
    

    另外,它告诉我们不要在不受信任的网络上使用如上配置进行vnc访问。如果有需求,可以进行更多的配置,使用ssh等进行保护。

  2. 修改root访问vnc的密码

vncpasswd root
  1. 启动vncserver(注意,启动前最好关闭防火墙和selinux,否则可能会被策略阻挡导致无法连接上)
systemctl start vncserver@:1
  1. 关闭防火墙,selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vi /etc/selinux/config

修改enforcingdisabled

  1. 启动后可以通过
systemctl status -l vncserver@:1

来查看vncserver服务的状态。

  1. 客户端下载vnc-viewerrealvnc等软件,进行访问,通过ip:1访问vnc服务端。

猜你喜欢

转载自blog.csdn.net/stpice/article/details/103774807