Skip to main content

How to install VNC server on Centos 7

VNC server is used to connect and control desktop environment of the server from remote clients. VNC viewer is used on remote computer to connect the server .
In the article we can learn about how to install vnc server on centos 7 . we can use the default packages provided in the centos yum repository.

Install vnc server on centos 7

Let’s start. If you don’t have desktop environment ( X windows ), issue the below commands one by one to install. It will take few minutes to install packages.
[[email protected] ~]# yum check-update
[[email protected] ~]# yum groupinstall "X Window System"
[[email protected] ~]# yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts
[[email protected] ~]# unlink /etc/systemd/system/
[[email protected] ~]# ln -sf /lib/systemd/system/ /etc/systemd/system/
[[email protected] ~]# reboot

After reboot, you will get Centos 7 desktop .

Now start installing VNC packages.
Step 1 » Issue the below command to install VNC package.
[[email protected] ~]# yum install tigervnc-server -y
Step 2 » Create a file vncserver@:1.service in /etc/systemd/system/ directory by copying example config file /lib/systemd/system/vncserver@.service
[[email protected] ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
Step 3 » Now open /etc/systemd/system/vncserver@:1.service file and replace with your username .
Find these lines ..
ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"

Replace ( Considering username as john )
ExecStart=/sbin/runuser -l john -c "/usr/bin/vncserver %i"

If you are creating for root user .
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"

Step 4 » Reload systemd for changes.
[[email protected] ~]# systemctl daemon-reload
Step 5 » Create VNC password for the user .
[[email protected] ~]# vncpasswd
Step 6 » Enable and start the service using the below commands.
Enable service at startup ( Permanent ).
[[email protected] ~]# systemctl enable vncserver@:1.service
Start the service .
[[email protected] ~]# systemctl start vncserver@:1.service
Step 7 » Allow VNC service in firewall.
[[email protected] ~]# firewall-cmd --permanent --add-service vnc-server
[[email protected] ~]# systemctl restart firewalld.service

Now you can able to connect VNC server using IP and Port ( Eg : )
install vnc server on centos 7
install VNC server Centos 7
You can use VNC client like Tightvnc viewer and Realvnc viewer to connect Server.
For additional users create files with different ports ( Refer Step 2 ) vncserver@:2.service by copying example config file and continue the steps 3,4,5 and 6 by replacing service name. Please make sure you logged in as that particular user for creating vnc password ( Step 5 ).

Additional Commands :

» To stop VNC service .
[[email protected] ~]# systemctl stop vncserver@:1.service
» To disable VNC service from startup ( permanent ).
[[email protected] ~]# systemctl disable vncserver@:1.service
» To stop firewall ( For troubleshooting ).
[[email protected] ~]# systemctl stop firewalld.service

Have a nice day

  • Faiz

    Gud one….., solved the root issue for me…..

  • Faiz

    Gud one….., solved the root issue for me…..

  • Girayhan Menekay

    its always entering Welcome to CentOS page, not to gui please help

  • Pingback: CENTOS 7 Media Server | Tinker Labz()

  • Girayhan Menekay

    problem solved, you need to edit init file for start gui on boot.

  • Simon Cheng

    You missed setting firewall…

  • Alberto Santos

    localhost.internal systemd[1]: Failed to start Remote desktop service (VNC).

    — Subject: Unit vncserver@:1.service has failed

    Remove this file if there is no X server
    : A VNC server is already running as :1

    .internal:1 is taken because of /tmp/.X11-unix/X1

    pam_unix(runuser-l:session): session opened for user root by (uid=0)

    hi i failed to start the vnc server any ideas?

  • Đàm Huy Mạnh

    How to open file in step 3?