Tutorial to Install and Use CentOS Remote Desktop on VPS Hosting

Time:2022-8-5

How telecommuting or remote flexible working is becoming more and more popular in the tech world. One technology behind this trend is remote desktop. Your desktop environment is in the cloud, and you can access your remote desktop anywhere you go, or at home or at work.

This tutorial describes how to set up a CentOS-based remote desktop in a VPS. Now, we will first show the basic environment of CentOS.

We assume you have created a CentOS 7 VPS instance (eg, using DigitalOcean or Amazon EC2). Please make sure your VPS instance has at least 1GB of RAM. Otherwise, CentOS will crash when you access the remote desktop.
2015529181050832.jpg (800×527)

Step 1: Install CentOS Desktop

If the CentOS version you are currently installing is a minimal version without a desktop, you will need to install a desktop on your VPS first (eg GNOME). For example, DigitalOcean's image is a minimal version, which requires a desktop GUI to be installed as follows

   

copy code

code show as below:

# yum groupinstall “GNOME Desktop”

Restart the VPS after the installation is complete.
Step 2: Install and configure the VNC server

The next step is to install and configure the VNC server. We are using TigerVNC, an open source VNC service implementation.

   

copy code

code show as below:

# yum install tigervnc-server

Now create a user account (eg: xmodulo) to access the remote desktop.

   

copy code

code show as below:

# useradd xmodulo
# passwd xmodulo

When a user tries to access a remote desktop using VNC, the VNC daemon is started to handle the request. This means you need to create a separate VNC profile for each user.

CentOS relies on systemd to manage and configure system services. So we will use systemd to configure the VNC server for user xmodulo.

First let's check the status of the VNC server using any of the following commands.

   

copy code

code show as below:

# systemctl status [email protected]:.service
# systemctl is-enabled [email protected]

By default, the newly installed VNC service is not activated (disabled).
2015529181116243.jpg (772×182)

Now copy a generic VNC service file to create a VNC service configuration for user xmodulo.

   

copy code

code show as below:

# cp <a>/lib/systemd/system/[email protected]</a> <a>/etc/systemd/system/[email protected]:1.service</a>

Open the configuration file with the text editor and replace under [Service] with the actual username (eg: xmodulo). same. Append the &quot;-geometry&quot; parameter to ExecStart. Finally, modify the lines &quot;ExecStart&quot; and &quot;PIDFile&quot; below.

   

copy code

code show as below:

# vi <a>/etc/systemd/system/[email protected]:1.service</a> </p>
<p> [Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c ‘/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :’
ExecStart=/sbin/runuser -l xmodulo -c “/usr/bin/vncserver %i -geometry 1024×768”
PIDFile=/home/xmodulo/.vnc/%H%i.pid
ExecStop=/bin/sh -c ‘/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :’

Now set a password for user xmodulo (optional). First switch to that user and run the vncserver command.

   

copy code

code show as below:

# su – xmodulo
# vncserver

You will be prompted for the user's VNC password. After the password is set, you will need to use this password to access your remote desktop next time.
2015529181148697.jpg (792×402)

Finally, reload the service to make the new VNC configuration take effect:

   

copy code

code show as below:

# systemctl daemon-reload

Automatically start the VNC service at boot:

   

copy code

code show as below:

# systemctl enable [email protected]:1.service

Check the port the vnc service is listening on:

    # netstat -tulpn | grep vnc 
   2015529181215821.jpg (784×180)
Port 5901 is the default port used by VNC clients to connect to the VNC server.
Step 3: Connect to the Remote Desktop via SSH

The Remote Frame Buffer (RFB) used by VNC is not a secure protocol by design, so it is not a good idea to connect directly to the VNC server on the VNC client. Any sensitive information such as passwords can be easily leaked in VNC traffic. Therefore, I strongly recommend using an SSH tunnel to encrypt your VNC traffic.

On the local machine where you want to run the VNC client, use the following command to create an SSH tunnel to the remote VPS. When asked to enter an SSH password, enter the user's password.

   

copy code

code show as below:

$ ssh [email protected]<VPS-IP-address> -L 5901:127.0.0.1:5901

Replace &quot;xmodulo&quot; with your own VNC username and fill in your own VPS IP address.

Once the SSH tunnel is established, remote VNC traffic is routed through the ssh tunnel and sent to 127.0.0.1:5901.

Now start your favorite VNC client (eg: vinagre) and connect to 127.0.0.1:5901.
2015529181241352.png (549×508)

You will be asked to enter the VNC password. When you enter the VNC password, you can securely connect to the CentOS remote desktop.
2015529181316444.jpg (800×492)

Then you will see the display as shown in the title image.

Recommended Today

Examples of how to use dates in Oracle

Table of contents foreword 1 Date equals\greater than\less than 2 Date difference calculation 1 Subtract two times directly 2 Two-layer conversion of time and date 3 Using the trunc function Summarize foreword When using sql functions, due to different project databases, the date usage methods in sql are quite different. Some common date calculations have […]