Configure VNC (Virtual Network Computing) for Remote Desktop in RHEL 8
In CentOS 8 / RHEL 8, GNOME is the default desktop environment. if you don’t have it in your system, install it using the following command:
[root@RHEL8 ~]# dnf groupinstall "workstation"
Or
[root@RHEL8 ~]# dnf groupinstall "Server with GUI"
Once the above packages are installed successfully then run the following command to enable the graphical mode
[root@RHEL8 ~]# systemctl set-default graphical
Now reboot the system so that we get GNOME login screen.
[root@RHEL8 ~]# reboot
Once the system is rebooted successfully uncomment the line “WaylandEnable=false” from the file “/etc/gdm/custom.conf” so that remote desktop session request via vnc is handled by xorg of GNOME desktop in place of wayland display manager.
VNC server will not work properly if SElinux is enabled on your system, as of now work around is to disable it using following commands,
[root@RHEL8 ~]# setenforce 0
[root@RHEL8 ~]# sed -i 's/enforcing/disabled/g' /etc/selinux/config
Step 2) Install VNC Server (tigervnc-server)
Next we’ll install the VNC Server, there are lot of VNC Servers available, and for installation purposes, we’ll be installing TigerVNC Server. It is one of the most popular VNC Server and a high-performance and platform-independent VNC that allows users to interact with remote machines easily.
Now install TigerVNC Server using the following command:
[root@RHEL8 ~]# dnf install tigervnc-server tigervnc-server-module -y
Step 3) Set VNC Password for Local User
Let’s assume we want ‘Vishnubane’ user to use VNC for remote desktop session, then switch to the user and set its password using vncpasswd command,
[root@RHEL8 ~]# su - Vishnubane
[Vishnubane@linuxtechi ~]$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
[Vishnubane@linuxtechi ~]$
[Vishnubane@linuxtechi ~]$ exit
logout
[root@RHEL8 ~]#
Step 4) Setup VNC Server Configuration File
Next step is to configure VNC Server Configuration file. Create a file “/etc/systemd/system/vncserver@.service” with the following content so that tigervnc-server’s service started for above local user “Vishnubane”.
[root@RHEL8 ~]# vim /etc/systemd/system/vncserver@.service
[Unit]
Description=Remote Desktop VNC Service
After=syslog.target network.target
[Service]
Type=forking
WorkingDirectory=/home/Vishnubane
User=Vishnubane
Group=Vishnubane
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i /dev/null 2 &1 || :'
ExecStart=/usr/bin/vncserver -autokill %i
ExecStop=/usr/bin/vncserver -kill %i
[Install]
WantedBy=multi-user.target
Save and exit the file,
Note: Replace the user name in above file which suits to your setup.
By default, VNC server listen on tcp port 5900+n, where n is the display number, if the display number is “1” then VNC server will listen its request on TCP port 5901.
Step 5) Start VNC Service and allow port in firewall
I am using display number as 1, so use the following commands to start and enable vnc service on display number “1”,
[root@RHEL8 ~]# systemctl daemon-reload
[root@RHEL8 ~]# systemctl start vncserver@:1.service
[root@RHEL8 ~]# systemctl enable vncserver@:1.service
Created symlink /etc/systemd/system/multi-user.target.wants/vncserver@:1.service → /etc/systemd/system/vncserver@.service.
[root@RHEL8 ~]#
Use below netstat or ss command to verify whether VNC server start listening its request on 5901,
[root@RHEL8 ~]# netstat -tunlp | grep 5901
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 8169/Xvnc
tcp6 0 0 :::5901 :::* LISTEN 8169/Xvnc
[root@RHEL8 ~]# ss -tunlp | grep -i 5901
tcp LISTEN 0 5 0.0.0.0:5901 0.0.0.0:* users:(("Xvnc",pid=8169,fd=6))
tcp LISTEN 0 5 [::]:5901 [::]:* users:(("Xvnc",pid=8169,fd=7))
[root@RHEL8 ~]#
Use below systemctl command to verify the status of VNC server,
[root@RHEL8 ~]# systemctl status vncserver@:1.service
Above command’s output confirms that VNC is started successfully on port tcp port 5901. Use the following command allow VNC Server port “5901” in os firewall,
[root@RHEL8 ~]# firewall-cmd --permanent --add-port=5901/tcp
success
[root@RHEL8 ~]# firewall-cmd --reload
success
[root@RHEL8 ~]#
Step 6) Connect to Remote Desktop Session
Now we are all set to see if the remote desktop connection is working. To access the remote desktop, Start the VNC Viewer from your Windows / Linux workstation and enter your VNC server IP Address and Port Number and then hit enter
Next, it will ask for your VNC password. Enter the password that you have created earlier for your local user and click OK to continue
Now you can see the remote desktop.
------------------------------------------------------
No comments:
Post a Comment