Hamsa K
Editor
6 min read | 4 months ago

How to Install and Configure VNC Server in Centos 7

Install and Configure VNC server in Centos 7

VNC (Virtual Network Computing) Server allows the remote Desktop sharing using remote VNC clients like VNC viewer. 

VNC server and client are not installed, by default. You need to setup the vnc server manually.

Prerequisites:

Before installing the VNC server, you would need install Gnome desktop.

Run the following commands if you are not using GSnome for your system.

[root@lampblogs ~]# yum group list
[root@lampblogs ~]# yum groupinstall "GNOME Desktop" 
[root@lampblogs ~]# ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
[root@lampblogs ~]# reboot(#Reboot the machine to start the server in the graphical mode#)

Step 1: Install vnc server

Tigervnc-server is a program which executes an Xvnc server and starts parallel sessions of Gnome or other Desktop Environment on the VNC desktop.

A started VNC user session can be accessed by same user from multiple VNC clients.

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

Step 2: Adding vnc user

In mycase i am adding one vnc user as kiran.you can replace with your own user

[root@lampblogs ~]# useradd kiran

Step3 : setup vnc configuration file

Copy the VNC server configuration file to /etc/systemd/system/ for configuring the system service. While copying, you can mention which port it should listen.

By default VNC server listens on 5900, but if you setup port-offset for VNC, you can run a service on a sub-port of the default port 5900.

For example, if you mention port 3, the desktop will be accessible on 5903.  You can connect the VNC server by specifying ipaddress:sub-port like below

ex: 192.168.0.13:3 or 192.168.0.13:5903

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

you need to edit the copied file.

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

At the end of the file,you can replace with your user information as below.

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

[Service] Type=forking

Clean any existing files in /tmp/.X11-unix environment

ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' ExecStart=/usr/sbin/runuser -l kiran -c "/usr/bin/vncserver %i" PIDFile=/home/kiran/.vnc/%H%i.pid ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install] WantedBy=multi-user.target

Step 4: Set Firewall Rule

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

Step 5: Set vnc password

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

[root@lampblogs ~]# su - kiran
[kiran@lampblogs ~]$ vncserver
You will require a password to access your desktops.
Password:
Verify:
xauth:  file /home/kiran/.Xauthority does not exist
New 'lampblogs.com:1 (kiran)' desktop is lampblogs.com:1
Creating default startup script /home/kiran/.vnc/xstartup
Creating default config /home/kiran/.vnc/config
Starting applications specified in /home/kiran/.vnc/xstartup
Log file is /home/kiran/.vnc/lampblogs.com:1.log

Step 6: start and enable vnc service

swithch to root user and start service with below commands

[kiran@lampblogs ~]$ su -
[root@lampblogs ~]# systemctl daemon-reload
[root@lampblogs ~]# systemctl start vncserver@:3.service
[root@lampblogs ~]# systemctl enable vncserver@:3.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:3.service to /etc/systemd/system/vncserver@:3.service.

Step 7: Access Remote Desktop Session

If you want to connect from ubuntu system use

ubuntu@localhost:~$ vncviewer 192.168.0.15:3

Open up a VNC viewer from Windows machine and enter a remote desktop address.

 

You will be asked to enter the password, enter the password that you have created earlier.Now Desktop session will get after authentication.

That’s All. You have successfully configured VNC server on centos/Rhel 7.

Remmina: Another popular VNC client for Linux based platforms is Remmina, is a remote desktop client is especially used in ubuntu/debian based distributions that run the GNOME desktop environment.

sudo apt-get install remmina

 



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy