How to Install and Configure VNC Server on CentOS
Set up TigerVNC on CentOS Stream, AlmaLinux or Rocky Linux: desktop, user mapping, the systemd service, and a safe connection through an SSH tunnel.
2 min readBy Swati
Reviewed by the AmazingRDP technical team

Need a Linux server to put a desktop on? A Linux VPS comes with root access. See Linux VPS from $6.99
VNC shows a graphical desktop of a Linux server on your own computer. On CentOS the usual server is TigerVNC. These steps are for CentOS Stream 8 and 9 and their relatives AlmaLinux and Rocky Linux. CentOS 7 reached its end of life in 2024 and used a different setup; do not start a new server on it.
1. Install a desktop
A server has no desktop for VNC to show. Install one (this downloads a lot):
sudo dnf groupinstall "Server with GUI"
You do not need to switch the server to graphical start-up. VNC starts its own desktop session.
2. Install TigerVNC
sudo dnf install tigervnc-server
3. Create the user and the VNC password
Do not run a desktop as root. Create a user, or use an existing one:
sudo adduser vncuser
sudo passwd vncuser
Sign in as that user and set the password VNC will ask for:
su - vncuser
vncpasswd
exit
Answer n to the question about a view-only password.
4. Give the user a display number
Each VNC desktop has a display number. Display :1 uses port 5901, :2 uses 5902, and so on. Open the mapping file:
sudo nano /etc/tigervnc/vncserver.users
Add this line:
:1=vncuser
5. Set the session options
As the VNC user, create the file ~/.vnc/config with:
session=gnome
geometry=1920x1080
localhost
localhost makes VNC accept connections from the server itself only. That is what you want: VNC traffic is not encrypted, so you will reach it through SSH (step 7) and never open its port to the internet.
6. Start the service
sudo systemctl enable --now vncserver@:1
sudo systemctl status vncserver@:1
The status should say "active (running)".
7. Connect through an SSH tunnel
On your own computer, open the tunnel and leave the window open:
ssh -L 5901:127.0.0.1:5901 vncuser@SERVER_IP
Then start a VNC viewer (TigerVNC Viewer or RealVNC Viewer, for example) and connect to:
127.0.0.1:5901
Enter the VNC password from step 3. The desktop appears, and everything travels inside the encrypted SSH connection. No firewall port has to be opened for VNC.
Problems and fixes
- The service fails to start. Read the log:
cat /home/vncuser/.vnc/*.log, andsudo journalctl -u vncserver@:1. A missing desktop (step 1) or a missing VNC password (step 3) are the usual causes. - A black or grey screen. The
session=line names a desktop that is not installed. List what exists withls /usr/share/xsessions/. - The user is also signed in on the server's own screen. One user cannot have two GNOME sessions. Sign out there, or use a separate user for VNC.
- "Connection refused" in the viewer. The tunnel window was closed, or the display number does not match the port.
Is VNC the right tool?
For administration, SSH is lighter and safer; most server work needs no desktop. Use VNC when a program truly needs a graphical screen. If what you want is a remote Windows desktop, Remote Desktop is smoother than VNC: see how to connect to RDP from a desktop. For the server itself, see Linux VPS plans. Related guides: fix "sudo: command not found" in Linux and copy and paste in Ubuntu Server.
Questions
Which port does VNC use?
Port 5900 plus the display number: display :1 uses 5901, display :2 uses 5902.
How do I change the VNC screen resolution?
Change the geometry= line in ~/.vnc/config and restart the service with sudo systemctl restart vncserver@:1.
How do I reset the VNC password?
Sign in as the VNC user and run vncpasswd again.
Is VNC secure?
Not by itself; its traffic is not encrypted. Keep it bound to localhost and connect through an SSH tunnel.