Skip to content

vm broker setup vnc server (ubuntu)

Allan Roger Reid edited this page Dec 19, 2023 · 3 revisions

Setup VNC Server on ubuntu

Setup tools

loginctl enable-linger ubuntu
sudo apt update
sudo apt install xfce4 xfce4-goodies -y
sudo apt install tigervnc-standalone-server -y

Run vncpasswd. Input a memorable password when prompted. Do not set a read-only password.

vncpasswd

Prepare systemd

cat << EOF > ~/.vnc/xstartup
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4 
EOF
chmod u+x ~/.vnc/xstartup

Setup systemd. Add the following file

sudo vi /etc/systemd/system/vncserver@.service
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple
User=ubuntu
PAMName=login
PIDFile=/home/%u/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver :%i -geometry 1440x900 -alwaysshared -fg -localhost no
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Start systemd

sudo systemctl daemon-reload
sudo systemctl stop vncserver@1.service
sudo systemctl enable vncserver@1.service
sudo systemctl start vncserver@1.service
sudo systemctl status vncserver@1.service

Connect

to hostname.domain:port where port was previously defined in the lxd node's streams definition e.g.

upstream perforce-bijan-vnc {
  server perforce-bijan.lxd:5901;
}

server {
  listen 20035;
  listen [::]:20035;
  proxy_pass perforce-bijan-vnc;
}

To reset

rm -rf /home/allan/.Xauthority-*
ps -ef | grep vnc .. kill
then restart `vncserver`
Clone this wiki locally