Wednesday, June 19, 2019

Install and Configure VNC Server in CentOS 7 and RHEL 7



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/vncserver@.service” 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/vncserver@.service /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


[root@tos02 ~]#  cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:4.service
[root@tos02 ~]#
[root@tos02 ~]# vi /etc/systemd/system/vncserver@:4.service
[root@tos02 ~]# firewall-cmd --permanent --zone=public --add-port=5904/tcp
success
[root@tos02 ~]# firewall-cmd --reload
success
[root@tos02 ~]# su - oracle
Last login: Wed Jun 19 20:06:37 IST 2019 on pts/0
[oracle@tos02 ~]$
[oracle@tos02 ~]$
[oracle@tos02 ~]$ vncserver

New 'tos02.tosh.com:1 (oracle)' desktop is tos02.tosh.com:1

Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/tos02.tosh.com:1.log

[oracle@tos02 ~]$ firewall-cmd --reload
Authorization failed.
    Make sure polkit agent is running or run the application as superuser.
[oracle@tos02 ~]$ exit
logout
[root@tos02 ~]#
[root@tos02 ~]# systemctl daemon-reload
[root@tos02 ~]# systemctl start vncserver@:4.service
[root@tos02 ~]# systemctl enable vncserver@:3.service
Failed to execute operation: File exists
[root@tos02 ~]# systemctl enable vncserver@:4.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:4.service to /etc/systemd/system/vncserver@:4.service.
[root@tos02 ~]# ln -s '/etc/systemd/system/vncserver@:4.service' '/etc/systemd/system/multi-user.target.wants/vncserver@:4.service'
ln: failed to create symbolic link Ć¢/etc/systemd/system/multi-user.target.wants/vncserver@:4.serviceĆ¢: File exists
[root@tos02 ~]#



[root@tos02 ~]# firewall-cmd --permanent --zone=public --add-port=5904/tcp
firewall-cmd --permanent --zone=public --add-port=5901/tcp
firewall-cmd --permanent --zone=public --add-port=5902/tcp
firewall-cmd --permanent --zone=public --add-port=5903/tcp
success
[root@tos02 ~]# firewall-cmd --reload
Success


SCREEN SETTING FULL MODE:
1.CONNECT vncviewer
2.screen will come
3.go to setting on top bar .
4.click option>display>custom setting and put 1340X710 .As per your screen adjust it.

PuTTY Fatal Error: expected key exchange group packet from server

PuTTY Fatal Error: expected key exchange group packet from server

I had this same issue and to fix it i change the key exchange algorithm.
In putty settings under connection->ssh->kex I moved Diffie-Hellman group 14 to the top of the list and Diffie-Helman group exchange to the bottom. this solved the issue.

-------------------------------------------------------------------------------

2nd:
You can enable logging of sshd which can give you more details about the error.

To enable logging:

Edit etc/ssh/sshd_config file and add the following line

LogLevel DEBUG2

Reload sshd config:

systemctl reload sshd

Debug message will be logged to the file /var/log/secure

tail -f /var/log/secure

--------------------------
https://www.opentechguides.com/askotg/question/106/putty-fatal-error-expected-key-exchange-group-packet-from-server

[ERROR]: The value of s_patch_service_name is not set correctly in atleast one of the context files.

[ERROR]: The value of s_patch_service_name is not set correctly in atleast one of the context files. I got the issue below wh...