How to install and access CentOS 7 Remote Desktop on VPS
Q: I want to install CentOS desktop in VPS and can remotely access the GUI desktop from my home. Is there any suggestions for setting and accessing CentOS Remote Desktop on VPS?
How to work remotely or remotely with elasticity is becoming increasingly popular in the technical field. One technology behind this trend is Remote Desktop. Your desktop environment is in the cloud. You can access your remote desktop anywhere you go, or at home or in the workplace.
This tutorial describes how to set up a CentOS-based Remote Desktop in VPS. Now, we will first display the Basic Environment of CentOS.
Assume that you have created a VPS instance for CentOS 7 (for example, DigitalOcean or Amazon EC2 ). Make sure that your VPS instance has at least 1 GB of memory. Otherwise, CentOS will crash when you access the Remote Desktop.
Step 1: Install CentOS Desktop
If the CentOS version you have installed does not have the minimum desktop version, you must first install the desktop (such as GNOME) on the VPS ). For example, the image of DigitalOcean is the minimum version, and it needs to install the desktop GUI as follows:
# yum groupinstall "GNOME Desktop"
After the installation is complete, restart the VPS.
Step 2: install and configure the VNC Server
Next, install and configure the VNC server. We use TigerVNC, an open-source VNC service implementation.
# yum install tigervnc-server
Create a user account (for example, xmodulo) to access the Remote Desktop.
# useradd xmodulo
# passwd xmodulo
When a user tries to use VNC to access the remote desktop, the VNC daemon starts to process the request. This means that you need to create an independent VNC configuration file for each user.
CentOS relies on systemd to manage and configure system services. Therefore, we will use systemd to configure the VNC Server for xmodulo.
First, let's use any of the following commands to check the status of the VNC server.
# systemctl status vncserver@:.service
# systemctl is-enabled vncserver@.service
By default, the installed VNC service is not activated (disabled ).
Copy a common VNC service file to create a VNC service configuration for xmodulo.
# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
Use the editor in this article to open the configuration file and replace the configuration file with the actual user name (for example, xmodulo) under [Service. Same. Append the "-geometry" parameter after ExecStart. Finally, modify the following "ExecStart" and "PIDFile" lines.
# vi /etc/systemd/system/vncserver@:1.service
[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 1024x768"
PIDFile=/home/xmodulo/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
Set the password for xmodulo (optional ). Switch to the user and run the vncserver command.
# su - xmodulo
# vncserver
You will be prompted to enter your VNC password. After the password is set, you need to use this password to access your remote desktop next time.
Finally, reload the service to make the new VNC configuration take effect:
# systemctl daemon-reload
The VNC service is automatically started at startup:
# systemctl enable vncserver@:1.service
Check the port on which the vnc service is listening:
# netstat -tulpn | grep vnc
Port 5901 is the default port used by the VNC client to connect to the VNC server.
Step 3: connect to the Remote Desktop through SSH
In terms of design, the remote frame cache (RFB) used by VNC is not a secure protocol, 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 disclosed 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 channel to connect to the remote VPS. Enter the SSH password.
$ ssh xmodulo@<VPS-IP-address>-L 5901:127.0.0.1:5901
Replace "xmodulo" with your own VNC user name and fill in your own vps ip address.
Once the SSH channel is established, the remote VNC traffic is routed through the ssh channel and sent to 127.0.0.1: 5901.
Start your favorite VNC client (such as vinagre) to connect to 127.0.0.1: 5901.
You will be asked to enter the VNC password. When you enter the VNC password, you can Securely connect to the CentOS Remote Desktop.
Then you will see the display of the question map.