1. Install X-Window
First we need to install X-Window , run the following command in the terminal, the installation will take a little time.
# yum check-update
# yum groupinstall "X Window System"
#yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts
### 设置默认启动图形界面
# unlink /etc/systemd/system/default.target
# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
# reboot
After the server restarts, we have a working CentOS 7 desktop environment.
Now, we are going to install the VNC server on the server.
2. Install VNC server
Now it's time to install the VNC server on our CentOS 7. We need to execute the following command.
# yum install tigervnc-server -y
3. Configure VNC
Then, we need /etc/systemd/system/
to create a configuration file in the directory. We can /lib/systemd/sytem/[email protected]
copy a sample configuration file.
# cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service
Then we open it with our favorite editor (here we use nano ) /etc/systemd/system/vncserver@:1.service
, find the following lines, and replace it with our username. For example, my username 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 with
ExecStart=/sbin/runuser -l linoxide -c "/usr/bin/vncserver %i"
PIDFile=/home/linoxide/.vnc/%H%i.pid
If it is root user then
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
Ok, let's restart systemd below.
# systemctl daemon-reload
Finally, set the user's VNC password. To set the password of a user, you must have the permission to switch to the user through sudo. Here I use the permission of linoxide and execute " su linoxide
".
# su linoxide
$ sudo vncpasswd
Make sure you enter a password with more than 6 characters