YouTube Icon

Code Playground.

How to Install and Configure VNC on CentOS 8

CFG

How to Install and Configure VNC on CentOS 8

Virtual Network Computing (VNC) is a graphical work area sharing framework that permits you to utilize your console and mouse to distantly control another PC. 

This article covers the means to introduce and design a VNC worker on CentOS 8. We'll likewise tell you the best way to safely interface with the VNC worker through a SSH burrow. 

Prerequisites

To track with this guide, you should be signed in as a client with sudo benefits on your distant CentOS machine. 

Installing Desktop Environment

For the most part, workers don't have a work area climate introduced. On the off chance that the machine you need to interface with doesn't have GUI, the initial step is to introduce it. Something else, skirt this progression. 

Run the accompanying order to introduce Gnome, the default work area climate in CentOS 8 on your distant machine: 

sudo dnf groupinstall "Server with GUI"

Contingent upon your framework, downloading and introducing the Gnome bundles and conditions may take some time. 

Installing VNC Server

TigerVNC is an effectively kept up elite open-source VNC worker. It is accessible in the default CentOS vaults, to introduce it type: 

sudo dnf install tigervnc-server

When the VNC worker is introduced, run the vncserver order to make the underlying design and set up the secret key. Try not to utilize sudo when running the accompanying order: 

vncserver

You will be incited to enter and affirm the secret key and whether to set it as a view-just secret phrase. On the off chance that you decide to set up a view-just secret key, the client won't have the option to interface with the VNC case with the mouse and the console. 

You will require a secret key to get to your work areas. 

You will require a password to access your desktops.

Password:
Verify:
Would you like to enter a view-only password (y/n)? n
/usr/bin/xauth:  file /home/cfg/.Xauthority does not exist

New 'server2.cfg.com:1 (cfg)' desktop at :1 on machine server2.cfg.com

Starting applications specified in /etc/X11/Xvnc-session
Log file is /home/cfg/.vnc/server2.cfg.com:1.log

The first run through the vncserver order is run, it will make and store the secret key record in the ~/.vnc index which will be made if not present. 

Note the :1 after the hostname in the yield above. This shows the showcase port number on which the VNC worker is running. For our situation, the worker is running on TCP port 5901 (5900+1). In the event that you make a subsequent occasion , it will run on the following free port i.e :2, whic implies that the worker is running on port 5902 (5900+2). 

What is essential to recall is that when working with VNC workers, :X is a presentation port that alludes to 5900+X. 

Prior to proceeding with the subsequent stage, first stop the VNC occurrence utilizing the vncserver order with a - execute choice and the worker number as a contention. For our situation, the worker is running in port 5901 (:1), so to stop it, run: 

vncserver -kill :1
Killing Xvnc process ID 19681

Configuring VNC Server

Since both Gnome and TigerVNC are introduced on the far off CentOS machine, the subsequent stage is to arrange TigerVNC to utilize Gnome. The VNC worker utilizes the ~/.vnc/xstartup record to dispatch applications while making another work area. Open the document: 

vim ~/.vnc/xstartup

And edit it as follows:

~/.vnc/xstartup

#!/bin/sh
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &

Spare and close the record . The content above is consequently executed at whatever point you begin or restart the TigerVNC worker. 

On the off chance that you need to pass extra alternatives to the VNC worker, open the ~/.vnc/config document and include one choice for each line. The most well-known choices are recorded in the document. Uncomment and adjust as you would prefer. 

~/.vnc/config

# securitytypes=vncauth,tlsvnc
# desktop=sandbox
geometry=1920x1080
# localhost
# alwaysshared

Making a Systemd unit record 

Unit records permit you to effortlessly begin, stop, and restart administrations. By and large, the best area to store client unit records is ~/.config/systemd/client. Make the registry : 

Creating a Systemd unit file

Duplicate the default vncserver unit record: 

mkdir -p ~/.config/systemd/user

Tell systemd that another client unit document exist: 

cp /usr/lib/systemd/user/vncserver@.service ~/.config/systemd/user/

Start the VNC administration and empower it at boot: 

systemctl --user daemon-reload

The number 1 after @: characterizes the showcase port on which the VNC administration will tune in. We are utilizing 1, which implies that the VNC worker will tune in on port 5901 as we talked about in the past segment. 

Empower waiting so the client administration begins at boot and continues running when the client isn't signed in: 

loginctl empower wait 

Confirm that the administration is effectively begun with: 

systemctl --user enable vncserver@:1.service --now
? vncserver@:1.service - Remote desktop service (VNC)
   Loaded: loaded (/home/cfg/.config/systemd/user/vncserver@.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-01-30 22:14:08 UTC; 2s ago
  Process: 20813 ExecStart=/usr/bin/vncserver :1 (code=exited, status=0/SUCCESS)
  Process: 20807 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill :1 > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
   CGroup: /user.slice/user-1000.slice/user@1000.service/vncserver.slice/vncserver@:1.service
  ...

Connecting to VNC server

VNC isn't a scrambled convention and can be dependent upon parcel sniffing. The prescribed methodology is to make a SSH passage to safely advance traffic from your neighborhood machine on port 5901 to the distant worker on a similar port. 

Set Up SSH Tunneling on Linux and macOS

On the off chance that you run Linux, macOS, or some other Unix-put together working framework with respect to your machine, you can without much of a stretch make a passage utilizing the accompanying ssh order: 

ssh -L 5901:127.0.0.1:5901 -N -f -l username remote_server_ip

You will be incited to enter the client secret phrase. 

Remember to supplant username and server_ip_address with your username and the IP address of your worker. 

Set Up SSH Tunneling on Windows

Windows clients can set up SSH Tunneling utilizing PuTTY . 

Open Putty and enter your worker IP Address in the Host name or IP address field. 

Under the Connection menu, grow SSH and select Tunnels. Enter the VNC worker port (5901) in the Source Port field, enter server_ip_address:5901 in the Destination field and snap on the Add button as appeared in the picture beneath: 

Return to the Session page to spare the settings so you don't have to enter them each time. To login to the distant worker, select the spared meeting and snap on the Open catch. 

Connecting using Vncviewer

To interface with the far off Server, open your VNC watcher and enter localhost:5901. 

You can utilize any VNC watcher, for example, TigerVNC, TightVNC, RealVNC, UltraVNC, Vinagre, and VNC Viewer for Google Chrome . 

We're utilizing TigerVNC: 

Enter the secret key when provoked, and you should see the default Gnome work area. It should look something like this: 

Thats't it! You would now be able to begin taking a shot at your far off work area from your nearby machine utilizing your console and mouse. 

Conclusion

We've told you the best way to arrangement a VNC worker and associate with a distant CentOS 8 machine. 

To begin a showcase for more than one client, rehash similar advances. Make the underlying setup, set up the secret word utilizing the vncserver order, and make another help record utilizing an alternate port. 

Don't hesitate to leave a remark in the event that you have any inquiries.




CFG