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-utils
Edit the following customization file to prevent GNOME using Wayland:
sudo nano /etc/gdm/custom.conf
and uncomment the line:
WaylandEnable=false
Finally, install TigerVNC
:
sudo dnf install tigervnc-server tigervnc-server-module
Configuration
Initiate the VNC
configuration:
vncserver
Set 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@.service
adding 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.target
save and exit.
In some other tutorials, the commands to kill an existing VNC session
/usr/bin/vncserver -kill %i
can be found written with a :
before the %i
, like this:
/usr/bin/vncserver -kill :%i
The 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.service
instead of:
vncserver@1.service
Next enable the recently created service:
sudo systemctl daemon-reload
sudo systemctl start vncserver@:1.service
sudo systemctl enable vncserver@:1.service
Now 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 --reload
You should be able to access the remote session using a VNC viewer, like TigerVNC viewer.