English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Centos7With CentOS6.x has changed greatly.
It took a lot of detours to install a remote desktop on a server. Writing this blog post is purely for record-keeping, so that in the future, if you encounter the same problem, you can trace it back.
1Assuming that no vnc software is installed on your system, the first step is to install vnc
yum -y install tigervnc-server tigervnc
2, CentOS7In the previous system, if you install vnc, you generally need to configure
[root@localhost ~]# cat /etc/sysconfig/vncservers # THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/[email protected]
However, as mentioned above, CentOS7The files that need to be configured are in
[root@localhost ~]# ll /lib/systemd/system/[email protected] -rw-r--r--. 1 root root 1744 Jun 10 14:15 /lib/systemd/system/[email protected]
3The file contains the following hints
# Quick HowTo: # 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service # 2. Edit <USER> and vncserver parameters appropriately # ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2) # 3reload`-. Run `systemctl daemon # 4. Run `systemctl enable vncserver@:<display>.service
4Copy a file and rename it to vncserver@:1.service
[root@localhost ~]# cp /lib/systemd/system/[email protected]/lib/systemd/system/vncserver@:1.service
5Replace <User> in the file with your current user, and replace %i with1
[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
6Update systemctl
systemctl daemon-reload
7Set to auto-start
systemctl enable vncserver@:1.service
8Start vnc service
systemctl start vncserver@:1.service
9Add the corresponding port to iptables5901Note, if there are other users, the port number also needs to be added. The default port for vnc is5900 + 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-prohibited COMMIT
Note:
1If you do not configure and enable the firewall and use VNC Viewer to connect at this time, it will report: "connect: Connection timed out(10060)"error."
2This article takes the root user as an example, if other users also need to log in, then, you also need to copy the file to
cp /lib/systemd/system/[email protected]/lib/systemd/system/vncserver@:2.service
At the same time, change %i in the file to2, and create a vncpasswd for the corresponding user.
3You can access it through UltraVNC, TigerVNC, or RealVNC Viewer, I am on win7using this3All tools can connect
Thank you for reading, I hope it can help everyone, thank you for your support to this site!