Install and Configure VNC Server in CentOS 7 and RHEL 7

VNC (Virtual Network Computing) Server allows the remote Desktop sharing using remote VNC clients like VNC viewer. In CentOS 7 & RHEL 7 package named “tigervnc-server” needs to be installed in order to setup the VNC server.

In this article we will go through the installation and configuration of VNC Server on CentOS 7 / RHEL 7.

Step:1 Make Sure the Desktop Packages are installed

In order to setup VNC server first we make sure that Desktop is installed ,in My case i am using Gnome Desktop. If Gnome Desktop is not installed on your Linux machine then use the below command to install.

[root@linuxtechi ~]# yum groupinstall "GNOME Desktop"

Step:2 Install Tigervnc and other dependency Package.

[root@linuxtechi ~]# yum install tigervnc-server xorg-x11-fonts-Type1

Step:3 Setup VNC Server Configuration File.

Copy the VNC config file “/lib/systemd/system/[email protected]” to the “/etc/systemd/system/vncserver@:<Port_Number>.service”.

While Copying the VNC config file we can mention the port number on which we want VNC service to be listen. In my case i am using port 3 , it means VNC will listen on “5903”. So while Connecting to the VNC server We can specify port number as <IP_Address_VNC_Server:3> or <IP_Address_VNC_Server:5903>

[root@linuxtechi ~]# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:3.service

Step:4 Update the User’s Information in the Config File

[root@linuxtechi ~]# vi /etc/systemd/system/vncserver@:3.service

vnc-server-config-file

Replace the “linuxtechi” user as per your requirement. In my case linuxtechi user will able to control and manage its desktop session using remote VNC clients.

Set the Firewall Rule if firewall is enabled on your linux box.

[root@linuxtechi ~]# firewall-cmd --permanent --zone=public --add-port=5903/tcp
success
[root@linuxtechi ~]# firewall-cmd --reload
success
[root@linuxtechi ~]#

Step:5 Set the VNC password for the User.

Switch to the user (linuxtechi) and run vncserver command to set the password as shown below :

vncserver-passwd

Start and Enable the VNC Service at boot.

Execute below commands as root only.

[root@linuxtechi ~]# systemctl daemon-reload
[root@linuxtechi ~]# systemctl start vncserver@:3.service
[root@linuxtechi ~]# systemctl enable vncserver@:3.service
ln -s '/etc/systemd/system/vncserver@:3.service' '/etc/systemd/system/multi-user.target.wants/vncserver@:3.service'
[root@linuxtechi ~]#

Step:6 Access Remote Desktop Session.

From Ubuntu Machine :

ubuntu@localhost:~$ vncviewer 192.168.1.15:3

Enter the VNC password that we have set in above step, after validating the authentication Remote Desktop session will start.

From Windows Machine Using VNC Viewer

Enter the VNC Server IP Address and Port Number and then Click on OK

vncviewer

Enter the VNC Password & then click on OK.

vnc-password

Desktop Session Will start after authentication.

remote-desktop-vncviewer

26 thoughts on “Install and Configure VNC Server in CentOS 7 and RHEL 7”

  1. Hi!

    I’m from Mexico. Thank you for your post. This is a good post, i can to installed and configured the vncserver

    Reply
  2. I did everything Exactly by the book, and ended here:
    [root@OptiPlex-380 ~]# systemctl daemon-reload
    [root@OptiPlex-380 ~]# systemctl start vncserver@:3.service
    Job for vncserver@:3.service failed because the control process exited with error code. See “systemctl status vncserver@:3.service” and “journalctl -xe” for details.
    [root@OptiPlex-380 ~]# systemctl status vncserver@:3.service
    ● vncserver@:3.service – Remote desktop service (VNC)
    Loaded: loaded (/etc/systemd/system/vncserver@:3.service; disabled; vendor preset: disabled)
    Active: failed (Result: exit-code) since Tue 2016-05-17 09:45:47 AEST; 44s ago
    Process: 1238 ExecStart=/usr/sbin/runuser -l david -c /usr/bin/vncserver %i (code=exited, status=2)
    Process: 1232 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)

    May 17 09:45:47 OptiPlex-380 systemd[1]: Starting Remote desktop service (VNC)…
    May 17 09:45:47 OptiPlex-380 systemd[1]: vncserver@:3.service: control process exited, code=exited status=2
    May 17 09:45:47 OptiPlex-380 systemd[1]: Failed to start Remote desktop service (VNC).
    May 17 09:45:47 OptiPlex-380 systemd[1]: Unit vncserver@:3.service entered failed state.
    May 17 09:45:47 OptiPlex-380 systemd[1]: vncserver@:3.service failed.

    Any hints? I’ve checked the forums I could find, with no clue. Any help greatly appreciated.

    Reply
  3. I’m a complete noob: Running CentOS 7 – Gnome installed. Followed all instructions. I entered the following;

    systemctl enable vncsever@:5901.service ln -s ‘/etc/systemd/system/vncserver@:5901.service’ ‘/etc/systemd/system/multi-user.target.wants/nvcserver@:5901.service’

    When I hit enter I get Failed to parse signal string /etc/systemd/system/vncserver@:5901.service

    Any help would be greatly appreciated!

    Reply
  4. Hi, I have a little problem. Everything went OK, but after
    systemctl start vncserver@:1.service

    I got this:

    Job for vncserver@:1.service failed because a configured resource limit was exceeded. See “systemctl status vncserver@:1.service” and “journalctl -xe” for details.

    I tried to remove /tmp/.X11-unix/

    without avail.

    Can somebody help. Thank

    Reply
  5. Great little guide – works like a champ. I like that if you follow the instructions exactly you’ll wind up with a VNC server that starts on host boot, and you can even login via the Gnome login… I’m printing this page to a PDF and stashing it. THANKS!

    Reply
  6. Instead of using “yum groupinstall “GNOME Desktop” , use below command to get rid of all issues. Follow rest other steps.

    yum groupinstall ‘Server with GUI

    yum groups mark install ‘X Window System’ ‘GNOME’

    systemctl set-default graphical.target

    Reply
  7. Thank you for your kind instruction. I could install both Vncserver on Centos 7 and Vncclient onWindows 10 successfully.

    Reply
  8. How about a light duty Window Manager. I dont want all the gnome stuff running on my server. TWM is not on the list anymore?

    Reply
  9. I had to create a vnc password for my user before the service would start properly on my RHEL 7.6 system. I created the user using vncpasswd while logged in with that user account.

    Reply
  10. I am getting the following error:
    Job for vncserver@:3.service failed because the control process exited with error code . See “Systemctl status vncserver@:3.service ” and “journalctl -xe” for details

    Reply
  11. I’m using VNC Viewer 6.20 to connect with success, using gnome graphical user interface on Red Hat 7.7 server. Connection completes with success but when I want to logout it ask for confirmation on the first attempt, with a timeout of 60 seconds to automatically disconnect.

    If I wait on the 60 seconds it disconnects but when I try to reconnect again I’m not able to connect, seems like session becomes frozen.
    If I don’t wait on the 60 seconds, and press the option to disconnect the session does not disconnect, and I still able to work on it but when I try to logout once again seems like the option has been disabled. If I just close the VNC viewer window and re-open the session, it comes right where I left when I closed the window.

    My question is: How I can make this VNC Viewer session to behave as expected when requesting the logout from the gnome interface?

    Thank you!

    Reply
  12. systemctl start vncserver@:1.service
    Job for vncserver@:1.service failed because a configured resource limit was exceeded. See “systemctl status vncserver@:1.service” and “journalctl -xe” for details.

    run below command to resolve this issue

    rm -f /tmp/.X11-unix/X1
    systemctl start vncserver@:1.service

    Reply
  13. vncserver@:2.service – Remote desktop service (VNC)
    Loaded: loaded (/etc/systemd/system/vncserver@:2.service; enabled; vendor preset: disabled)
    Active: failed (Result: protocol) since Fri 2020-07-31 14:38:01 EDT; 3min 1s ago
    Process: 5814 ExecStart=/sbin/runuser -l copuser -c /usr/bin/vncserver :2 -geometry 1280×1024 (code=exited, status=0/SUCCESS)
    Process: 5810 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill :2 > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)

    Jul 31 14:37:58 dev-rhel8-tew.gccsj.nn.c2fse.northgrum.com systemd[1]: Starting Remote desktop service (VNC)…
    Jul 31 14:38:01 dev-rhel8-tew.gccsj.nn.c2fse.northgrum.com systemd[1]: vncserver@:2.service: Can’t open PID file /home/copuser/.vnc/dev-rhel8-tew.gccsj.nn.c2fse.northgrum.com:2.pid (yet?) after start: No such file or directory
    Jul 31 14:38:01 dev-rhel8-tew.gccsj.nn.c2fse.northgrum.com systemd[1]: vncserver@:2.service: Failed with result ‘protocol’.
    Jul 31 14:38:01 dev-rhel8-tew.gccsj.nn.c2fse.northgrum.com systemd[1]: Failed to start Remote desktop service (VNC).

    Reply
  14. Thanks for the post. I was struggling as in other links where it was mention,
    $ su –
    $ vncpasswd

    but as in your post step-5,
    #su –
    #vncserver
    It works for me. i.e. “vncserver” command.

    my vncserver service unit file is

    [vncu1@vnc-test ~]$sudo cat /etc/systemd/system/vncserver@:6.service

    #####################################################
    [Unit]
    Description=Remote desktop service (VNC)
    After=syslog.target network.target

    [Service]
    Type=simple

    # Clean any existing files in /tmp/.X11-unix environment
    ExecStartPre=/bin/sh -c ‘/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :’
    ExecStart=/usr/bin/vncserver_wrapper %i
    ExecStop=/bin/sh -c ‘/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :’

    [Install]
    WantedBy=multi-user.target
    #####################################################

    here Type=simple

    Reply

Leave a Reply to Pablo Cancel reply