VNC access is based on VNC desktop sessions started by the service file we just created. To grant remote access to another user, you need to create another service file /etc/systemd/system/vncserver@:2.service for next available port-offset which is 5902.
Update the firewall rules to allow the VNC connection. The following rule will allow our port-offset 5901 so that VNC viewer can connect to CentOS 7.
Start VNC server after switching to user linuxbees and set the password for VNC.
[linuxbees@server ~]$ vncserver
You will require a password to access your desktops.
Would you like to enter a view-only password (y/n)? N
A view-only password is not used
xauth: file /home/linuxbees/.Xauthority does not exist
New 'server.linuxbees.local:1 (linuxbees)' desktop is server.linuxbees.local:1
Creating default startup script /home/linuxbees/.vnc/xstartup
Creating default config /home/linuxbees/.vnc/config
Starting applications specified in /home/linuxbees/.vnc/xstartup
Log file is /home/linuxbees/.vnc/server.linuxbees.local:1.log
Enable VNC Server
Switch to the root user.
Reload the systemctl daemon as root.
Start the VNC service as root.
systemctl start vncserver@:1.service
Enable it on system startup as root.
systemctl enable vncserver@:1.service
Check the VNC service status.
systemctl status vncserver@:1.service
● vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-04-22 08:51:31 IST; 6min ago
Main PID: 6514 (Xvnc)
‣ 6514 /bin/Xvnc :1 -auth /home/linuxbees/.Xauthority -desktop server.linuxbees.local:1 (linuxbees) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x768 -pn -rfbauth /home/lin...
Apr 22 08:50:56 server.linuxbees.local systemd: Starting Remote desktop service (VNC)...
Apr 22 08:51:32 server.linuxbees.local systemd: Started Remote desktop service (VNC).
Access VNC Desktop
Open up a VNC viewer from Windows machine and enter a remote desktop address.
VNC viewer will prompt you for the password. Enter the password that you have created a few steps back.
Now you should get the VNC desktop session of user linuxbees.
That’s All. You have learned how to install VNC server on CentOS 7 and connect to the VNC desktop session using VNC viewer. Share your feedback in the comments section.