How to install and configure a VNC Server on CentOS 7.0
This is a tutorial on how to install and configure the VNC service on your CentOS 7. Of course, this tutorial is also suitable for RHEL 7. In this tutorial, we will learn what VNC is and how to install and configure the VNC Server on CentOS 7.
As we all know, as a system administrator, servers are managed over the network most of the time. The graphic interface is rarely used in server management. In most cases, we only use SSH to complete our management tasks. In this article, we will configure VNC to provide a method to connect to our CentOS 7 server. VNC allows us to enable a remote graphic session to connect to our server, so that we can remotely access the server's graphical interface through the network.
VNC Server is a free and open source software that allows users to remotely access the desktop environment of the server. In addition, you must use the VNC viewer client to connect to the VNC server.
Advantages of some VNC servers:
- Remote graphical management makes work easy and convenient.
- The clipboard can be shared between the CentOS server host and the VNC client host.
- You can also install graphical tools on the CentOS server to make management more powerful.
- Once the VNC client is installed, you can use any operating system to manage the CentOS server.
- It is more reliable than ssh graphic forwarding and RDP connections.
So, let's get started with VNC Server installation. Follow the steps below to build an available VNC.
First, we need an available desktop environment (X-Window). If not, we need to install one first.
Note: The following commands must be run as root. To switch to the root user, Run "sudo-s" on the terminal, excluding double quotation marks ("").
1. install X-Window
First, we need to install X-Window and run the following command on the terminal. It takes a little time to install X-Window.
# yum check-update
# yum groupinstall "X Window System"
#yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts
### Set the default startup Gui
# unlink /etc/systemd/system/default.target
# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
# reboot
After the server is restarted, we have a working CentOS 7 desktop environment.
Now we have to install the VNC server on the server.
2. Install the VNC Server
Now we have to install the VNC Server on CentOS 7. We need to execute the following command.
# yum install tigervnc-server -y
3. Configure VNC
Then, we need/etc/systemd/system/
Create a configuration file in the directory. We can/lib/systemd/sytem/vncserver@.service
Copy a configuration file example.
# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
Then we use our favorite editor (Here we use nano) to open/etc/systemd/system/vncserver@:1.service
Find the following lines and replace them with your username. For example, my user name is linoxide, So I replaced it with linoxide:
ExecStart=/sbin/runuser -l <USER>-c "/usr/bin/vncserver %i"
PIDFile=/home/<USER>/.vnc/%H%i.pid
Replace
ExecStart=/sbin/runuser -l linoxide -c "/usr/bin/vncserver %i"
PIDFile=/home/linoxide/.vnc/%H%i.pid
For root users
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
Now, restart systemd.
# systemctl daemon-reload
Finally, you must set the user's VNC password. To set a password for a user, you must have the permission to switch to the user through sudo. Here, I use the permission of linoxide to execute"su linoxide
.
# su linoxide
$ sudo vncpasswd
Make sure that you enter more than 6 Characters in the password
4. enable the Service
Run the following command (permanently) to enable the Service:
$ sudo systemctl enable vncserver@:1.service
Start the service.
$ sudo systemctl start vncserver@:1.service
5. Firewall settings
We need to configure a firewall to make the VNC service work normally.
$ sudo firewall-cmd --permanent --add-service vnc-server
$ sudo systemctl restart firewalld.service
Now you can use the IP address and port number (for example, 192.168.1.1: 1). The port here is not the server port, but is sorted from 1 according to the number of VNC connections) to connect to the VNC server.
6. Use a VNC client to connect to the server
Now the VNC server has been installed. To connect to the server using VNC, we also need a VNC client installed on the local computer that is only used to connect to the remote computer.
You can use clients like Tightvnc viewer and Realvnc viewer to connect to the server.
To use more user connections, you need to create a configuration file and port. Go Back To Step 1 and add a new user and port. You need to createvncserver@:2.service
Replace the username in the configuration file and the corresponding file name and port number in the subsequent steps. Make sure that you log on to the VNC server using the user name you used when configuring the VNC password.
The VNC service uses the port 5900. Given that different users use VNC, different ports are obtained for each connection. The number in the configuration file name tells the VNC server to run the service on the sub port 5900. In this example, the first VNC service runs on port 5901 (5900 + 1), increases in sequence, and runs on port 5900 + x. X indicates the user's configuration file name.vncserver@:x.service
X.
Before establishing a connection, we need to know the IP address and port of the server. An IP address is a unique identification number of a computer in the network. The IP address of my server is 96.126.120.92, And the VNC user port is 1.
Run the following command to obtain the Internet IP address of the server (LCTT: If your server is placed on the Intranet or uses a dynamic IP address, you can obtain its Internet IP address ).
# curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
Summary
Now we have installed and configured the VNC server on the server running CentOS 7/RHEL 7. VNC is the simplest tool for free open-source software to remotely control servers. It is also an excellent substitute for Teamviewer Remote Access. VNC allows a user installed with a VNC client to remotely control a server installed with the VNC service. The following are some frequently used commands. Have fun!
Other commands:
VNC installation Configuration
Install and configure VNC in CentOS 6.3
In Linux, the dependency installation VNC is not detected.
CentOS6 VNC service installation and configuration
Configure and install VNC in CentOS
VNC remote control installation and Setup
Windows accesses Ubuntu through VNC
Install VNC for accessing Ubuntu 12.04 through Windows Remote Desktop