CentOS 7 Install TigerVNC Server

Keywords: vnc Oracle sudo firewall

1. CentOS 7 Install TigerVNC Server

This paper describes how to install VNC Server on CentOS 7 for remote access.This article refers to DigitalOcean The tutorial includes some installation experience.

2. Install TigerVNC Server

Non-root user installation is recommended, -y for direct installation

sudo yum install -y tigervnc-server

3. Configure VNC Service

The following is a new method, which used to configure / etc/sysconfig/vncservers. Now the first step is to copy the file provided by default to / etc/systemd/system with the following commands

sudo cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

Next, modify the configuration file

sudo vim /etc/systemd/system/vncserver@:1.service

Replace <USER> with the user name you want. I'm oracle here, adding the resolution setting parameter - geometry 1280x720, as follows

# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service
# 2. Edit <USER> and vncserver parameters appropriately
#   ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#

. . .

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[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 oracle -c "/usr/bin/vncserver %i -geometry 1280x720" 
PIDFile=/home/oracle/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

Save the file, exit vim, reload the configuration

sudo systemctl daemon-reload

It can also be set to boot-up

sudo systemctl enable vncserver@:1.service

4. Modify the firewall

First determine if firewalld is started, enter the following command to determine

sudo firewall-cmd --state

If startup should output

running

If not running, execute the following command

sudo systemctl start firewalld

Add port number 5901-5905

sudo firewall-cmd --permanent --zone=public --add-port=5901-5905/tcp

Reload Firewall

sudo firewall-cmd --reload

You can use the following commands to see if a port number has been added

firewall-cmd --list-all-zones

5. Set the VNC password

Log in to the server with the oracle user name by ssh and execute the following command

vncserver

The terminal will prompt you to enter the password as follows

You will require a password to access your desktops.
Password:
Verify:
xauth:  file /home/oracle/.Xauthority does not exist

New 'localhost.localdomain:1 (oracle)' desktop is localhost.localdomain:1

Creating default startup script /home/oracle/.vnc/xstartup
Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/localhost.localdomain:1.log

If you want to change your password, you can use vncpasswd.There is already a vnc service running, but we need to start with the service we just configured, so we need to kill the vnc service we just started with the following command.

vncserver -kill :1

Next, restart the service we configured

sudo systemctl daemon-reload
sudo systemctl restart vncserver@:1.service

Use the following command to see if the service is running correctly

sudo systemctl status vncserver@:1.service -l

If started correctly, the output should be

● vncserver@:2.service - Remote desktop service (VNC)
   Loaded: loaded (/etc/systemd/system/vncserver@:2.service; enabled; vendor preset: disabled)
   Active: active (running) since day 2017-07-23 21:55:35 CST; 12h ago
  Process: 8720 ExecStart=/usr/sbin/runuser -l oracle -c /usr/bin/vncserver %i -geometry 1280x720 (code=exited, status=0/SUCCESS)
  Process: 8716 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
 Main PID: 8744 (Xvnc)
   CGroup: /system.slice/system-vncserver.slice/vncserver@:2.service
           ‣ 8744 /usr/bin/Xvnc :2 -desktop 127.0.0.1:2 (oracle) -auth /home/oracle/.Xauthority -geometry 1280x720 -rfbwait 30000 -rfbauth /home/oracle/.vnc/passwd -rfbport 5902 -fp catalogue:/etc/X11/fontpath.d -pn

7month 23 21:55:32 127.0.0.1 systemd[1]: Starting Remote desktop service (VNC)...
7 February 23 21:55:35 127.0.0.1 systemd[1]: Started Remote desktop service (VNC).

If you want to configure multi-user simultaneous access, you need to change the above vncserver@:1.service to vncserver@:2.service, then configure the user name, resolution parameters, and follow my steps again.

Posted by trekerboy on Tue, 11 Jun 2019 10:08:20 -0700