- CentOS 7 Install the TigerVNC Server
This article describes how to install VNC Server on CentOS 7 for remote access. This article takes a look at DigitalOcean’s tutorial and adds some installation tips.
- Install TigerVNC Server
You are advised to use a non-root user. -y indicates direct installation
sudo yum install -y tigervnc-server1
- Configure VNC Service
The following method is a new method, is used to configure the/etc/sysconfig/vncservers, now the first step is the default file is copied to the/etc/systemd/system, the command is as follows
sudo cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service1
Next modify the configuration file
sudo vim /etc/systemd/system/vncserver@:1.service1
Replace it with the username you want, in this case oracle, and add the parameter -Geometry 1280×720 to set the resolution, all as follows
# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@:.service
# 2. Edit and vncserver parameters appropriately
# (“runuser -l -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 1280×720”
PIDFile=/home/oracle/.vnc/%H%i.pid
ExecStop=/bin/sh -c ‘/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :’
[Install]
WantedBy=multi-user.target1234567891011121314151617181920212223242526
Save the file and exit vim to reload the configuration
sudo systemctl daemon-reload1
Can also be set to boot
sudo systemctl enable vncserver@:1.service1
- Modifying a Firewall
To check whether Firewalld is started, run the following command
sudo firewall-cmd –state1
Should output if started
running1
If it is not running, run the following command
sudo systemctl start firewalld1
Add the port number 5901-5905
sudo firewall-cmd –permanent –zone=public –add-port=5901-5905/tcp1
Reload the firewall
sudo firewall-cmd –reload1
You can use the following command to check whether the port number is added
firewall-cmd –list-all-zones1
- Setting the VNC Password
Log in to the server using SSH as user oracle and run the following command
vncserver1
The terminal will prompt you for your 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.log12345678910
If you want to change the password, use vncpasswd. There is already a VNC service running, but we need to use the newly configured service to start, so we need to kill the VNC service and use the following command.
vncserver -kill :11
Next, restart the service we configured
sudo systemctl daemon-reload
sudo systemctl restart vncserver@:1.service12
Use the following command to check that the service is running correctly
sudo systemctl status vncserver@:1.service -l1
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 1280×720 (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/. xauthor-Geometry 1280×720-rfbwait 30000 -rfbauth /home/oracle/.vnc/passwd -rfbport 5902 -fp catalogue:/etc/X11/fontpath.d -pn
7月 23 21:55:32 127.0.0.1 SystemD [1]: Starting Remote Desktop Service (VNC)…
7月 23 21:55:35 127.0.0.1 SystemD [1]: Started Remote Desktop Service (VNC)
123456789101112
If you want to configure the simultaneous access of multiple users, you need to change the above vncserver@:1.service to vncserver@:2.service, and then configure the user name and resolution parameters, and then follow my steps again