(Ubuntu Server without Default Desktop/DM) install and configure TightVNC on Ubuntu 18.04
Start and Stop Ubuntu VNC Server
To start a VNC session with desktop ID 1, run:
tightvncserver :1 -geometry 1366x768 -depth 24
tightvncserver :2 -geometry 1366x768 -depth 24
To manually stop the VNC Server on your Ubuntu 18.04 server, run the command tightvncserver -kill and provide the same ID you used when starting the VNC Server.
tightvncserver -kill :1
Automatically Starting the VNC Server on Ubuntu 18.04
Perform the following steps to ensure that the Ubuntu VNC Server will automatically start when your Ubuntu 18.04 server rebooted.
Create a new systemd unit file called vncserver@1.service under the /etc/systemd/system directory.
sudo vim /etc/systemd/system/vncserver@1.service
Insert the following lines:
[Unit]
Description=Start a VNC Session at startup With Desktop ID 1
After=multi-user.target network.target
[Service]
Type=forking
# IMPORTANT!!! Change 'username' to actual user that connect to the session
User=<your_username>
ExecStartPre=/bin/sh -c '/usr/bin/tightvncserver -kill :%i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/tightvncserver :%i -geometry 1366x768 -depth 24
ExecStop=/usr/bin/tightvncserver -kill :%i
[Install]
WantedBy=multi-user.target
Reload the systemd and enable the vncserver@1.service:
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
Disable the service If you don't want to start the VNC session when your Ubuntu 18.04 server rebooted:
sudo systemctl disable vncserver@1.service