Install requirements
sudo apt update && sudo apt upgrade -y
sudo apt install xfce4 xfce4-goodies dbus-x11 -y
sudo apt install tigervnc-standalone-server tigervnc-common -y
Create a user for desktop use. For this example, I will use the username “user1”.
useradd -m -s /bin/bash user1
usermod -aG sudo user1
passwd user1
switch to the user
su - user1
Start vncserver
vncserver :1 -geometry 1920x1080 -depth 24 -localhost no
Stop vncserver
vncserver -kill :1
Create the VNC startup script and make it executable
mkdir -p ~/.vnc
touch ~/.vnc/xstartup && chmod +x ~/.vnc/xstartup
vi ~/.vnc/xstartup
Add
#!/bin/bash
xrdb $HOME/.Xresources
export XDG_SESSION_TYPE=x11
export DISPLAY=:1
vncconfig -nowin &
exec dbus-launch --exit-with-session startxfce4
Save and exit.
Create a service file
sudo vi /etc/systemd/system/vncserver@.service
Add
[Unit]
Description=TigerVNC server
After=syslog.target network.target
[Service]
Type=simple
User=user1
WorkingDirectory=/home/user1
Environment=HOME=/home/user1
Environment=DISPLAY=:%i
Environment=XAUTHORITY=/home/user1/.Xauthority
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || true'
ExecStart=/usr/bin/vncserver :%i -geometry 1920x1080 -depth 24 -localhost no -fg
ExecStop=/usr/bin/vncserver -kill :%i
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
Enable and restart vncserver
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
sudo systemctl start vncserver@1.service
You can restart the server, you will be able to connect to VNC Server on your-server-ip:1
VNC use simple password, to avoid brute force attacks. Protect VNC with a firewall, only allow whitelisted IP’s connect to port 5901, or use SSH tunnel to connect to VNC server.

Leave a Reply