CentOS 8 - How to set up VNC server
Intro
In this tutorial I’ll show you how to configure a remote desktop session, using VNC in CentOS 8.
Install needed packages
Install the desktop environment:
sudo dnf groupinstall "Server with GUI"Install some other handy tools:
sudo dnf install nano tmux wget cifs-utilsEdit the following customization file to prevent GNOME using Wayland:
sudo nano /etc/gdm/custom.confand uncomment the line:
WaylandEnable=falseFinally, install TigerVNC:
sudo dnf install tigervnc-server tigervnc-server-moduleConfiguration
Initiate the VNC configuration:
vncserverSet a password that will be used to access the Remote session.
Now create a service file, to enable VNC to run automatically when rebooting the machine:
sudo nano /etc/systemd/system/vncserver@.serviceadding the following text, changing the user name (in this case pier) to the appropriate user name:
[Unit]
Description=Remote Desktop VNC Service
After=syslog.target network.target
[Service]
Type=forking
WorkingDirectory=/home/pier
User=pier
Group=pier
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -autokill %i
ExecStop=/usr/bin/vncserver -kill %i
[Install]
WantedBy=multi-user.targetsave and exit.
In some other tutorials, the commands to kill an existing VNC session
/usr/bin/vncserver -kill %ican be found written with a : before the %i, like this:
/usr/bin/vncserver -kill :%iThe service file mentioned above will not have this, as the name of the running service will contain the columns in it, i.e.:
vncserver@:1.serviceinstead of:
vncserver@1.serviceNext enable the recently created service:
sudo systemctl daemon-reload
sudo systemctl start vncserver@:1.service
sudo systemctl enable vncserver@:1.serviceNow we need to enable the remote client to connect to the server using a TCP connection, hence opening the firewall port:
sudo firewall-cmd --permanent --add-port=5901/tcp
sudo firewall-cmd --reloadYou should be able to access the remote session using a VNC viewer, like TigerVNC viewer.