Friday, June 3, 2016

RHEL7: Install and configure a VNC server

Install and configure a VNC server on RHEL7

VNC server is used to access the server remotely using GUI. There are some instances where you will need graphical interface to install some software/tools such as Oracle, SAS. Once you configure and set up your vnc server, you will use VNC client to access the server.

Note: Before you start installation process, create your repo
Make Sure you have Desktop Packages are installed
# yum groupinstall "GNOME Desktop"

1. Install VNC server package.
# yum search vnc
# yum install tigervnc-server

2. Upon installation, it creates a sample config file at /lib/systemd/system/vncserver@.service. You have to copy it it to /etc/systemd/system directory or create your own.

3. Copy the config file to /etc/systemd/system/ directory
# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service

Note: When you copy the config file, you can also use port number on target location such as destination file can be like vncserver@:2.service. By default vnc server listens on 5900. By specifying the 2.service, you are specifying to use the port 2, wheni turn out to be 5902. So, you can access vnc server from client using the vncserver:2 or 192.168.10.120:2 or 192.168.10.120:5902

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

If you want to set it for multiple user, copy the sample config as follow
# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver-user1@1:.service
# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver-user2@2:.service

Note: ports are going to be 5901 and 5902. Once copied, following the instruction below

4. Edit the config file and change the following <USER> to your userid on line 41 and 42.

# vi /etc/systemd/system/vncserver@\:2.service
 ExecStart=/usr/sbin/runuser -l kamal -c "/usr/bin/vncserver %i"
 PIDFile=/home/kamal/.vnc/%H%i.pid

wq!

5. Create VNC password to your user

[root@sam yum.repos.d]# su - kamal
Last login: Thu Jun  2 12:10:05 EDT 2016 from suvi.expanor.local on pts/0
[kamal@sam ~]$ vncserver

You will require a password to access your desktops.

Password:
Verify:
xauth:  file /home/kamal/.Xauthority does not exist

New 'sam.expanor.local:1 (kamal)' desktop is sam.expanor.local:1

Creating default startup script /home/kamal/.vnc/xstartup
Starting applications specified in /home/kamal/.vnc/xstartup
Log file is /home/kamal/.vnc/sam.expanor.local:1.log

[kamal@sam ~]$

6. add service/port to firewall config if its enabled
# systemctl status firewalld
# firewall-cmd --permanent --zone=public --add-port=5902/tcp
# firewall-cmd --reload
or
# firewall-cmd --add-rich-rule='rule family="ipv4" service name=vnc-server accept'


7. Start and enable VNC server service
# systemctl daemon-reload
# systemctl enable vncserver@:2.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:2.service to /etc/systemd/system/vncserver@:2.service.


[root@sam yum.repos.d]# systemctl start vncserver@:2.service
Warning: vncserver@:2.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@sam yum.repos.d]# systemctl daemon-reload
[root@sam yum.repos.d]# systemctl enable vncserver@:2.service


8. Now, check the ports vnc is listening on
# netstat -tulp | grep vnc


9. Now, go to your client system and connect
From Linux machine
$ vncviewer 192.168.10.120:2

On windows machine,
go to download page of tightvnc viewer (TightVNC Java Viewer JAR in a ZIP archive) and run the program.
http://www.tightvnc.com/download.php

Once open, supply the following information
Remote host: 192.168.10.120
Port: 5902

and click connect, it will prompt for password.
and it may ask for administrator password. enter the administrator password.
Enter your login name and password to login to your system.

No comments:

Post a Comment