I've been struggling with getting a completely self-sustaining VNC server working on Ubuntu mate, and I'd like some advice from anyone who has been down this road before. My target platform is Ubuntu Mate, and it is a combination of VM's and old laptops that may still have local sessions. I've landed on TigerVNC due to dynamic resolution support (to eventually pair with apache Guacamole), and specifically do NOT want to use x0vncserver as I want this to be separate from the local session should one exist on the laptops.
Ideally, this would be a systemd service for a couple of users. To the best I can tell, I would need a different systemd unit file per user account, which is fine (it'd be easy enough to create a mapping for user to session across systems; when you start a session my user could always be display 10 at 5910 and my wife's could be 11 at 5911, etc). I have seen a LOT of struggle with this, particularly in recent ubuntu, because of some changes. Specifically, this cannot be a user systemd service as those do not run until the user logs in, and I want these started at boot. I've followed these guides below:
https://bytexd.com/how-to-install-configure-vnc-server-on-ubuntu/
https://superuser.com/a/1724271
At this time, my systemd unit looks like this:
/etc/systemd/system/vncserver.service
[Unit]
Description=TigerVNC Server
After=syslog.target network.target
[Service]
Type=simple
User=surfrock66
Group=surfrock66
WorkingDirectory=/home/surfrock66
PIDFile=/home/surfrock66/.vnc/%H%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i
ExecStart=/usr/bin/vncserver -localhost no :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
At this time, my xstartup file looks like this:
#!/bin/sh
unset DBUS_SESSION_BUS_ADDRESS
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
/usr/bin/mate-session
This works when my user launches the vncserver from the terminal, but when launching from a systemd service, it fails to start. I believe this is somehow due to user environment variables not being set; I've seen some guides recommending running the execStart commands as "su -l surfrock66 " to force the user's environment, but I have nothing to support that. Here's the front of the log file for the systemd service when I try to start it:
Oct 17 15:58:11 hostname.subdomain.domain.com vncserver[12983]: New Xtigervnc server 'hostname.subdomain.domain.com:1 (surfrock66)' on port 5901 for display :1.
Oct 17 15:58:11 hostname.subdomain.domain.com vncserver[12983]: Use xtigervncviewer -SecurityTypes VncAuth,TLSVnc -passwd /tmp/tigervnc.WITIzx/passwd hostname.subdomain.domain.com:1 to connect to the VNC server.
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activating service name='org.a11y.Bus' requested by ':1.0' (uid=1000 pid=12995 comm="x-window-manager")
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Successfully activated service 'org.a11y.Bus'
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activating service name='org.freedesktop.systemd1' requested by ':1.4' (uid=1000 pid=12996 comm="/usr/bin/mate-session")
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
Oct 17 15:58:11 hostname.subdomain.domain.com org.a11y.Bus[13008]: dbus-daemon[13008]: Activating service name='org.a11y.atspi.Registry' requested by ':1.0' (uid=1000 pid=12995 comm="x-window-manager")
Oct 17 15:58:11 hostname.subdomain.domain.com org.a11y.Bus[13008]: dbus-daemon[13008]: Successfully activated service 'org.a11y.atspi.Registry'
Oct 17 15:58:11 hostname.subdomain.domain.com org.a11y.Bus[13024]: SpiRegistry daemon is running with well-known name - org.a11y.atspi.Registry
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activating service name='org.freedesktop.systemd1' requested by ':1.5' (uid=1000 pid=12996 comm="/usr/bin/mate-session")
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activating service name='org.freedesktop.systemd1' requested by ':1.5' (uid=1000 pid=12996 comm="/usr/bin/mate-session")
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activating service name='org.freedesktop.systemd1' requested by ':1.5' (uid=1000 pid=12996 comm="/usr/bin/mate-session")
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activating service name='ca.desrt.dconf' requested by ':1.5' (uid=1000 pid=12996 comm="/usr/bin/mate-session")
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Successfully activated service 'ca.desrt.dconf'
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activating service name='org.freedesktop.systemd1' requested by ':1.5' (uid=1000 pid=12996 comm="/usr/bin/mate-session")
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activating service name='org.freedesktop.systemd1' requested by ':1.5' (uid=1000 pid=12996 comm="/usr/bin/mate-session")
Oct 17 15:58:11 hostname.subdomain.domain.com dbus-daemon[13000]: [session uid=1000 pid=12998] Activated service 'org.freedesktop.systemd1' failed: Process org.freedesktop.systemd1 exited with status 1
Oct 17 15:58:11 hostname.subdomain.domain.com mate-session[12996]: WARNING: Could not parse desktop file /home/surfrock66/.config/autostart/wicd-tray.desktop: Key file does not have key “Name” in group “Desktop Entry”
Oct 17 15:58:11 hostname.subdomain.domain.com mate-session[12996]: GLib-GObject-CRITICAL: Custom constructor for class GsmAutostartApp returned NULL (which is invalid). Please use GInitable instead.
Oct 17 15:58:11 hostname.subdomain.domain.com mate-session[12996]: WARNING: could not read /home/surfrock66/.config/autostart/wicd-tray.desktop
Oct 17 15:58:11 hostname.subdomain.domain.com mate-session[12996]: WARNING: Unable to find provider 'marco-compton' of required component 'windowmanager'
Oct 17 15:58:11 hostname.subdomain.domain.com mate-session[12996]: WARNING: Unable to find provider '' of required component 'dock'
This is a good breakdown. A firehose relay takes TB's of storage and is not practical for self-hosting, and AppView isn't hostable yet: https://alice.bsky.sh/post/3laega7icmi2q