⽤你当前的⽤户替换,将%i替换为1[Unit]
Description=Remote desktop service (VNC)After=syslog.target network.target[Service]Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l root -c \"/usr/bin/vncserver :1 -geometry 1280x720 -depth 24\"PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'[Install]
WantedBy=multi-user.target
6、更新systemctlsystemctl daemon-reload7、设置为⾃动启动
systemctl enable vncserver@:1.service8、启动vnc服务
systemctl start vncserver@:1.service
9、在iptables中加⼊对应的端⼝5901(注意,如果有其他⽤户,那么也需要将端⼝加上。vnc的端⼝默认是5900 + n)
[root@localhost system]# cat /etc/sysconfig/iptables# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT-A INPUT -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT
注意:
1、如果你不配置和启⽤防⽕墙,此时⽤VNC Viewer连接的话,会报:\"connect:Connection timed out(10060)\"错误。2、本⽂是以root⽤户为例,如果其他⽤户也需要登录,那么,还需要将⽂件复制为cp /lib/systemd/system/vncserver@.service/lib/systemd/system/vncserver@:2.service同时,将⽂件内的%i改为2,并建⽴对应⽤户的vncpasswd。
3、你可以通过UltraVNC,TigerVNC或者RealVNC Viewer进⾏访问,我在win7下使⽤这3中⼯具均能连接感谢阅读,希望能帮助到⼤家,谢谢⼤家对本站的⽀持!