Showing posts with label VNC. Show all posts
Showing posts with label VNC. Show all posts

Wednesday, February 8, 2017

How To Install VNC Server On CentOS 7 & RHEL 7

In this post, you can find the step by step method of installation and configuration of VNC server on CentOS 7 / RHEL 7. VNC server installation on CentOS 7 / RHEL 7 is quite different from older version of linux.

Before moving to installation part, first we need to know what is VNC server and how it is works on Linux environment.

VNC (Virtual Network Computing):

VNC stands for Virtual Network Computing server which allows for remote desktop connection in graphical GUI mode by using their remote client. For VNC client we can use VNC viewer. We can use other VNC client as wll for taking a remote connection of VNC server.  Some packages is required for installation and configuration which we explain during the post.

Step by Step Installation and Configuration method for VNC Server:

First we need to install the required packages on the server. You can install the packages using "YUM" command and if you have source package you can install it. On my machine I have yum repo , so we can install the rpm using YUM.

1. In my machine I am using GNOME desktop, if GNOME desktop is not installed on your machine then you need to install it by using below command.

#yum groupinstall "GNOME Desktop"

Using above command you can install all the packages which are required for desktop version. When you run the above command you can see all listed packages before installation.

2. After installation of GNOME packages we will install tigervnc-server packages which is mandatory for VNC server installation.

#yum install tigervnc-server*

here, "*" sign is used for all dependency, if you use this sign it is automatically installed all dependency. Using above command we can install all the VNC server rpm's.

3. Now we will add VNC user on the server.

#useradd vibhor

In my case I used my name but you can use any name.

4. In CentOS 7,there is change in the vncserver configuration file, becuase in older version of CentOS it was /etc/sysconfig/vncservers and now it have changed in /lib/systemd/system/vncserver@.service

#cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service

5. Now we will edit the vncserver file as describe below.

#vi /etc/systemd/system/vncserver@:2.service

[...]
[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=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
#PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStart=/sbin/runuser -l vibhor -c "/usr/bin/vncserver %i"
PIDFile=/home/vibhor/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

In the above file, you need to set the user name which use add on the server for access the VNC server. You can add more user on the server but for each user you need to create new service file and in each file you will change the user string.

6. If your firewall is enable on your machine then you need to add VNC server service on the firewall and make a permanent, in my machine it is enable so i will use it.

#firewall-cmd --permanent --zone=public --add-service vnc-server
#firewall-cmd --reload

7.  Now please switch the user from root and start the vnc server for vnc user.

#su - vibhor

vibhor@localhost~]$ vncserver

You will require a password to access your desktops.

Password:<--yourvncpassword
Verify:<--yourvncpassword
xauth:  file /home/vibhor/.Xauthority does not exist

New 'localhost:2 (vibhor)' desktop is localhost:2

Creating default startup script /home/vibhor/.vnc/xstartup
Starting applications specified in /home/vibhor/.vnc/xstartup
Log file is /home/vibhor/.vnc/localhost:2.log

It is creating the file in your home direcotory , if you see the service is startup and working fine.

8. Now please start the all required services for vnc server and make it permanent so once you take a reboot of machine it is not disable. All the service start and enable through root user.

#systemctl daemon-reload
#systemctl enable vncserver@:2.service
#systemctl start vncserver@:2.service

9. Now  go to your workstation or laptop and install the VNC client and connect the server using "vibhor" vnc user. when you run the client it is asking for host name so you will enter the host name and enter the vncuser password after that you can connect the server graphically.