There are different flavors of VNC, but I will proceed with describing setup of TightVNC.
First, verify you are using Xfce4. I use XUbuntu 21.10, in this case, which defaults to XFCE. Check for it with this command:
sudo apt list --installed | grep xfce4
NOTE: I had trouble getting this config to work without xfce4 on the standard Ubuntu.
Next install TightVNC like so:
sudo apt upgrade & sudo apt update
sudo apt install xfce4-goodies
sudo apt install tightvncserver ssh openssl
Then run:
vncpassword
echo -e '#!/bin/bash \nxrdb $HOME/.Xresources \nstartxfce4 & \n'
At this point you could run the vncserver
command to start it up, but instead we want to run as a service. So, create this service file, but fix the 4 instances of sammy
username in this file to match your system user/group:
#/etc/systemd/system/vncserver@.service
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target
[Service]
Type=forking
User=sammy
Group=sammy
WorkingDirectory=/home/sammy
PIDFile=/home/sammy/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
In that config, I suppressed the use of the -localhost
argument so that the VNC service will listen , and allow, on port 5901 from all remote hosts.
Then run these commands once:
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
sudo vncserver -kill :1
sudo systemctl start vncserver@1
sudo systemctl status vncserver@1
Now, from a remote computer, connect to this service on port 5901 from a VNC client on another computer.