Install VNC server on Centos 7
VNC is a good remote tool, whether based on Windows or Linux, Because I recently learned about Centos, therefore, we are going to build a VNC server on Centos 7 so that I can remotely connect to the server from the client through VNC viewer.
If you have not installed the desktop environment (X Windows), you can run the following command to install the packages. It may take several minutes to install the packages.
[root@localhost~]
#yumcheck-update
[root@localhost~]
#yumgroupinstall"XWindowsSystem"
[root@localhost~]
#yuminstallgnome-classic-sessiongnome-terminalnautilus-open-terminalcontrol-centerliberation-mono-fonts
[root@localhost~]
#unlink/etc/systemd/system/default.target
[root@localhost~]
#ln
-sf
/lib/systemd/system/graphical
.target
/etc/systemd/system/default
.target
[root@localhost~]
#reboot
After restart, you can enter the Centos 7 desktop environment.
Step 1 enter the following command to install the VNC package
[root@localhost~]
#yuminstalltigervnc-server-y
Step 2 create a file vncserver @: 1. service in the/etc/systemd/system/directory, and copy the instance configuration file/lib/systemd/system/vncserver @. service
[root@localhost~]
#cp/lib/systemd/system/vncserver@.service/etc/systemd/system/vncserver@:1.service
Step 3 open and edit the/etc/systemd/system/vncserver @: 1. service file and replace the user item with your username.
[Service]
Type=forking
#Cleananyexistingfilesin/tmp/.X11-unixenvironment
ExecStartPre=
/bin/sh
-c
'/usr/bin/vncserver-kill%i>/dev/null2>&1||:'
ExecStart=
/sbin/runuser
-lroot-c
"/usr/bin/vncserver%i"
PIDFile=
/root/
.vnc/%H%i.pid
Note that the root account is used for login, so change <user> to root
Step 4 restart systemd
[root@localhostsystem]
#systemctldaemon-reload
Step 5 create a VNC password for the user
[root@localhostsystem]
#vncpasswd
Here, the password I created is 123456.
Step 6 enable and start the service
[root@localhostsystem]
#systemctlenablevncserver@:1.service
ln
-s
'/etc/systemd/system/vncserver@:1.service'
'/etc/systemd/system/multi-user.target.wants/vncserver@:1.service'
[root@localhostsystem]
#systemctlstartvncserver@:1.service
Step 7 allow the VNC service to pass the Firewall
[root@localhost~]
#firewall-cmd--permanent--add-servicevnc-server
[root@localhost~]
#systemctlrestartfirewalld.service
Now I can remotely view the graphical interface of Centos 7 through the VNC viewer client running on Win10.
We can see the desktop environment of Centos 7.
To stop the VNC service, enter the following command.
[root@localhost~]
#systemctlstopvncserver@:1.service
Disable the VNC service from the system (permanent)
[root@localhost~]
#systemctldisablevncserver@:1.service
Stop the Firewall Service
[root@localhost~]
#systemctlstopfirewall.service
Have a nice day!