Introduction

VNC, or “Virtual Network Computing”, is a connection system that allows you to use your keyboard and mouse to interact with a graphical desktop environment on a remote server. It makes managing files, software, and settings on a remote server easier for users who are not yet comfortable with the command line.

TS Environment

xilongj@xlnx-ubu01:~$ service ufw status
● ufw.service - Uncomplicated firewall
   Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: enabled)
   Active: active (exited) since Mon 2020-03-30 22:05:46 CST; 32s ago
  Process: 1434 ExecStop=/lib/ufw/ufw-init stop (code=exited, status=0/SUCCESS)
  Process: 1481 ExecStart=/lib/ufw/ufw-init start quiet (code=exited, status=0/SUCCESS)
 Main PID: 1481 (code=exited, status=0/SUCCESS)

Mar 30 22:05:46 xlnx-ubu01 systemd[1]: Starting Uncomplicated firewall...
Mar 30 22:05:46 xlnx-ubu01 systemd[1]: Started Uncomplicated firewall.
xilongj@xlnx-ubu01:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

https://mirrors.aliyun.com

root@xlnx-ubu01:~# cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

Install Xfce and TightVNC

root@xlnx-ubu01:~# apt-get update -y
root@xlnx-ubu01:~# apt install xfce4 xfce4-goodies tightvncserver -y
xilongj@xlnx-ubu01:~$ vncserver

You will require a password to access your desktops.

Password:
Warning: password truncated to the length of 8.
Verify:
Would you like to enter a view-only password (y/n)? n

New 'X' desktop is xlnx-ubu01:1

Creating default startup script /home/xilongj/.vnc/xstartup
Starting applications specified in /home/xilongj/.vnc/xstartup
Log file is /home/xilongj/.vnc/xlnx-ubu01:1.log

Stop VNC Server

xilongj@xlnx-ubu01:~$ netstat -lntup
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      18041/Xtightvnc
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      18041/Xtightvnc
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 ::1:6010                :::*                    LISTEN      -
xilongj@xlnx-ubu01:~$ vncserver -kill :1
Killing Xtightvnc process ID 18041

  

xilongj@xlnx-ubu01:~$ cd .vnc/
xilongj@xlnx-ubu01:~/.vnc$ ls -l
total 12
-rw------- 1 xilongj xilongj   8 Mar 30 22:12 passwd
-rw-rw-r-- 1 xilongj xilongj 686 Mar 30 22:12 xlnx-ubu01:1.log
-rwxr-xr-x 1 xilongj xilongj 225 Mar 30 22:12 xstartup
xilongj@xlnx-ubu01:~/.vnc$
xilongj@xlnx-ubu01:~/.vnc$ vim xstartup
xilongj@xlnx-ubu01:~/.vnc$ cat xstartup
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &

Start VNC Server

xilongj@xlnx-ubu01:~$ vncserver -depth 24 -geometry 1920x1080

New 'X' desktop is xlnx-ubu01:1

Starting applications specified in /home/xilongj/.vnc/xstartup
Log file is /home/xilongj/.vnc/xlnx-ubu01:1.log

xilongj@xlnx-ubu01:~$ netstat -lntup
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:5901          0.0.0.0:*               LISTEN      18236/Xtightvnc
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      18236/Xtightvnc
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 ::1:6010                :::*                    LISTEN      -

 

xilongj@xlnx-ubu01:~$ cat /etc/systemd/system/vncserver@.service
[Unit]
Description=Start TightVNC Server
After=syslog.target network.target

[Service]
Type=forking
User=xilongj
PAMName=login
PIDFile=/home/xilongj/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

 

xilongj@xlnx-ubu01:~$ sudo systemctl daemon-reload
xilongj@xlnx-ubu01:~$ systemctl enable vncserver@1.service

 

Video Demo: 

https://www.bilibili.com/video/BV1W64y1u7r2/