xRDP protocol is a bit slow to connect based on my previous testing. This time, I am trying to use VNC protocol to do connection, which has been proven much faster than xRDP.

My previous post “Connect to GNOME desktop environment via xRDP on CentOS 7 & Ubuntu 18” shows how to use RDP client connecting to linux but connection speed is too slow for regular operation. Compared both, VNC solution is much better for daily operation remote control experience when using it on Linux server.

Pre-requirements


1 Update CentOS
yum update -y

2 Enable Password Authentication (Not Secure)

$ sudo passwd netsec


$ vi etc/ssh/sshd_config 

PasswordAuthentication yes

3  Increase Swap partition file size

https://blog.51sec.org/2020/03/change-swap-size-to-improve-low-memory.html

[root@centos7-zabbix-client ~]# sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
1048576+0 records in
1048576+0 records out
1073741824 bytes (1.1 GB) copied, 27.5052 s, 39.0 MB/s
[root@centos7-zabbix-client ~]# sudo chmod 600 /swapfile
[root@centos7-zabbix-client ~]# sudo mkswap /swapfile
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=d126e13f-162d-4a1d-998c-f8e4152e4f8b
[root@centos7-zabbix-client ~]# sudo swapon /swapfile
[root@centos7-zabbix-client ~]# vi /etc/fstab

Add a new line into /etc/fstab file:
/swapfile swap swap defaults 0 0

4  Create a new VNC user 
useradd -m -s /bin/bash john
passwd john

usermod -a -G wheel john
su – john
sudo su

Install xfce and vnc server

Before installing the XFCE desktop, install the latest EPEL repository.
yum -y install epel-release
Now install the XFCE desktop using the yum command below.
yum groupinstall Xfce -y
After the installation is complete, install the ‘tigervnc-server’ package.
yum -y install tigervnc-server
Wait until the installation is complete.

Initial VNC Configuration 

su – john

mv ~/.vnc/xstartup ~/.vnc/xstartup.bekup
vi ~/.vnc/xstartup

Paste the configuration below.
#!/bin/bash
 xrdb $HOME/.Xresources
 startxfce4 &
exit vi, copy the default ‘Xresources’ configuration in the ‘john’ user home directory.
cp /etc/X11/Xresources ~/.Xresources
And make the ‘xstartup’ script executable by changing its access permissions. Then run the ‘vncserver’ command again.
chmod +x ~/.vnc/xstartup
vncserver
Now, the new vnc session is running with our default desktop XFCE.

vncserver

vncserver -list

Running TigerVNC as a Service

Copy the vncserver unit file with the cp command:
sudo cp /usr/lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service
Open the file with your text editor, edit the lines highlighted in yellow and edit it as show below
sudo vi /etc/systemd/system/vncserver@\:1.service

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
User=john

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver %I
PIDFile=/home/john/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target
Save and close the file. Notify systemd that we created a new unit file with:
sudo systemctl daemon-reload
The next step is to enable the unit file with the following command:
sudo systemctl enable vncserver@:1.service
The number 1 after the @ sign defines the display port on which the VNC service will run. In this example, that is the default 1, and the VNC server will listen on port 5901.
Start the VNC service by executing:
sudo systemctl start vncserver@:1.service
Verify that the service is successfully started with:
sudo systemctl status vncserver@:1.service

Configure VNCViewer to Connect to Server

YouTube Video:

By Jon

Leave a Reply

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

%d