Skip to content

Setup VNC connection to server

Allan Roger Reid edited this page Dec 4, 2024 · 2 revisions

Remote Desktop

Install Setup tools

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

OPTIONAL Prepare systemd

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

Test and OPTIONAL Kill vncserver

vncserver
vncserver -list
vncserver -kill :1

OPTIONAL 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

OPTIONAL 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

LXC only 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;
}

Run on Local machine e.g. login with the password set before

ssh -L 5901:127.0.0.1:5901 -N -f -l allan 1.2.3.4 -p 4492

or another example

ssh -L 5901:127.0.0.1:5901 -N -f -l allan allanroger.ddns.net

Download and install vnc viewer locally. Connect to localhost:5901

image image

To reset

rm -rf /home/allan/.Xauthority-*
pkill Xtigervnc

Run vncserver again or systemctl restart vncserver

image

Clone this wiki locally