Introduction:
A Virtual Network Computing (VNC) server allows you to access your CentOS 8 server’s graphical desktop remotely. This can be incredibly useful for various tasks, such as administering servers with graphical user interfaces or troubleshooting GUI-related issues. In this guide, we’ll walk you through the process of installing and configuring a VNC server on CentOS 8.
Prerequisites:
Before you begin, ensure that you have:
- A CentOS 8 server with root or sudo access.
- A terminal or SSH client to connect to the server.
Step 1: Update the System:
Start by updating your system’s package list and upgrading installed packages to their latest versions:
sudo dnf update
Step 2: Install the VNC Server:
CentOS 8 provides TigerVNC, a popular VNC server. Install it using the following command:
sudo dnf install tigervnc-server
Step 3: Configure the VNC Server:
Once the installation is complete, configure the VNC server by creating a VNC user’s password. Replace <username>
with your desired username:
sudo vncpasswd /etc/vncpasswd
You will be prompted to set a password for VNC access.
Step 4: Create a VNC Service Unit:
To manage the VNC server as a service, create a systemd service unit file. Replace <username>
with your username:
sudo nano /etc/systemd/system/vncserver@:1.service
Add the following configuration to the file:
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver :1 -geometry 1280x720 -alwaysshared -localhost no -fg
ExecStop=/usr/bin/vncserver -kill :1
[Install]
WantedBy=multi-user.target
Save your changes and exit the text editor.
Step 5: Enable and Start the VNC Service:
Enable the VNC service unit and start the VNC server:
sudo systemctl enable --now vncserver@:1
Step 6: Configure Firewall (Optional):
If you have a firewall enabled on your CentOS 8 server, open the VNC port (5901) to allow incoming connections:
sudo firewall-cmd --add-service=vnc-server --permanent
sudo firewall-cmd --reload
Step 7: Connect to the VNC Server:
You can use a VNC client like RealVNC or TightVNC to connect to your CentOS 8 server. Enter the server’s IP address followed by :1
(the display number) as the address, e.g., your_server_ip:1
.
When prompted, enter the VNC password you set earlier.
Conclusion:
You’ve successfully installed and configured a VNC server on your CentOS 8 system, allowing you to access the graphical desktop remotely. This can be particularly useful for server administration and troubleshooting tasks. Ensure that you secure your VNC server by using strong passwords and, if necessary, configuring SSH tunneling for added security.