Centos7 install vncserver

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.

  1. # yum check-update
  2. # yum groupinstall "X Window System"

installing x windows

  1. #yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts

install gnome classic session

  1. ### 设置默认启动图形界面
  2. # unlink /etc/systemd/system/default.target
  3. # ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

configuring graphics

  1. # 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.

  1. # yum install tigervnc-server -y

vnc server

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.

  1. # cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service

copying vnc server configuration

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:

  1. ExecStart=/sbin/runuser -<USER>-"/usr/bin/vncserver %i"
  2. PIDFile=/home/<USER>/.vnc/%H%i.pid

replace with

  1. ExecStart=/sbin/runuser -l linoxide -"/usr/bin/vncserver %i"
  2. PIDFile=/home/linoxide/.vnc/%H%i.pid

If it is root user then

  1. ExecStart=/sbin/runuser -l root -"/usr/bin/vncserver %i"
  2. PIDFile=/root/.vnc/%H%i.pid

configuring user

Ok, let's restart systemd below.

  1. # 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".

  1. # su linoxide
  2. $ sudo vncpasswd

setting vnc password

Make sure you enter a password with more than 6 characters

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327099104&siteId=291194637