multi user vncserver
Table of Contents
Let’s setup an Ubuntu 24.04 Server and give multiple users to it using VNC.
So, I have an Ubuntu 24.04 server in the lab, and I need to get multiple users to VNC in. Not my favourite way to use a UNIX system, but all the hardware tools are graphical, and this is the way design is done.
To keep things light, we will use lightdm
greeter and xfce4
desktop.
I’m assuming that you know how to setup Linux user accounts, SSH server, SSH keys, and all that stuff.
Initial System Preparation #
-
Update system:
1sudo apt update 2sudo apt upgrade -y
-
Install lightweight desktop and display manager:
1sudo apt install xfce4 xfce4-goodies lightdm -y
Select lightdm during installation.
-
Install extra fonts:
1sudo apt install xfonts-base xfonts-75dpi xfonts-100dpi xfonts-scalable -y
-
Install dummy video driver:
1sudo apt install xserver-xorg-video-dummy -y
-
Configure
/etc/X11/xorg.conf
:1Section "Device" 2 Identifier "Configured Video Device" 3 Driver "dummy" 4 VideoRam 256000 5EndSection 6 7Section "Monitor" 8 Identifier "Configured Monitor" 9 HorizSync 5.0 - 1000.0 10 VertRefresh 5.0 - 200.0 11 Modeline "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync 12 Option "PreferredMode" "1920x1080_60.00" 13EndSection 14 15Section "Screen" 16 Identifier "Default Screen" 17 Monitor "Configured Monitor" 18 Device "Configured Video Device" 19 DefaultDepth 24 20 SubSection "Display" 21 Depth 24 22 Viewport 0 0 23 Virtual 1920 1080 24 Modes "1920x1080_60.00" 25 EndSubSection 26EndSection
-
Enable graphical boot:
1sudo systemctl set-default graphical.target 2sudo reboot
-
Disable LightDM (to avoid conflicts):
1sudo systemctl stop lightdm 2sudo systemctl disable lightdm
… this is optional, but I don’t need any local logins.
-
Purge GNOME/Ubuntu desktop:
1sudo apt purge gnome* ubuntu-desktop -y 2sudo apt autoremove -y
… it’s slow over VNC.
-
Purge Wayland packages:
1sudo apt purge wayland* libwayland* -y 2sudo apt autoremove -y
-
Set XFCE as default session for all future users:
1echo -e "[Desktop]\nSession=xfce.desktop" > /etc/skel/.dmrc
-
Set XFCE as default session (for each existing user):
1echo -e "[Desktop]\nSession=xfce.desktop" > ~/.dmrc
Disable Suspend and Power Management #
-
Mask suspend targets:
1sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
-
Configure XFCE power manager (
/etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-power-manager.xml
):1<?xml version="1.0" encoding="UTF-8"?> 2 3<channel name="xfce4-power-manager" version="1.0"> 4 <property name="power-manager" type="empty"> 5 <property name="inactivity-on-ac" type="uint" value="0"/> 6 <property name="inactivity-sleep-mode-on-ac" type="int" value="0"/> 7 </property> 8</channel>
… without this change, XFCE would suspend the system when idle.
-
Disable LightDM greeter suspend (install dbus-x11 first):
1sudo apt install dbus-x11 -y 2sudo -u lightdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing' 3sudo -u lightdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0 4sudo -u lightdm dbus-launch gsettings set org.gnome.desktop.session idle-delay 0 5sudo systemctl restart lightdm
… if you disabled lightdm above you don’t need this.
Handle Notifications and Snap #
-
Fix xfce4-notifyd (
/etc/systemd/user/xfce4-notifyd.service.d/override.conf
):1[Service] 2Environment="DISPLAY=:0"
1sudo systemctl daemon-reload 2sudo systemctl restart lightdm
… only restart if you still have lightdm enabled.
-
Remove snapd-desktop-integration:
1sudo snap remove snapd-desktop-integration
… optional, but it spamming my logs with messages.
TigerVNC Installation and Configuration #
-
Install TigerVNC:
1sudo apt install tigervnc-standalone-server tigervnc-common -y
-
Make VNC start
xfce4
desktop for any future user:- Edit
/etc/skel/.vnc/xstartup
:then1#!/bin/sh 2unset SESSION_MANAGER 3unset DBUS_SESSION_BUS_ADDRESS 4exec startxfce4
1chmod +x /etc/skel/.vnc/xstartup
- Edit
-
For each user:
- Edit
~/.vnc/xstartup
:then1#!/bin/sh 2unset SESSION_MANAGER 3unset DBUS_SESSION_BUS_ADDRESS 4exec startxfce4
1chmod +x ~/.vnc/xstartup
- Edit
-
Create
/etc/systemd/user/vncserver@.service
:1[Unit] 2Description=VNC Server for display :%i 3After=network.target 4 5[Service] 6Type=simple 7ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :' 8ExecStart=/usr/bin/vncserver :%i -geometry 1920x1080 -depth 24 -localhost no -SecurityTypes Plain -pam_service login -fg 9ExecStop=/usr/bin/vncserver -kill :%i 10Restart=always 11 12[Install] 13WantedBy=default.target
-
Enable linger for each user:
1sudo loginctl enable-linger <user>
(this lets systemd session live longer than the ssh login)
-
Now, each user will get a port to connect to and an Xserver. You will need to map these.
For example, if I have 3 users I might have:
username X session # TCP port bob 1 5901 frank 2 5902 joe 3 5903 -
As each user, and not as root, enable and start service:
1systemctl --user daemon-reload 2systemctl --user enable vncserver@<X> 3systemctl --user start vncserver@<X>
(replace
<X>
with X session number of that user)
Firewall Configuration #
- Allow VNC ports from VPN subnet:
1sudo ufw allow from 10.0.0.0/8 to any port 5900:5999 proto tcp 2sudo ufw reload
Connection #
- From another system, connect with TigerVNC client:
1vncviewer -SecurityTypes Plain <server-ip>:590<N>
- Use system username and password for authentication.
Working around snaps #
Both Firefox and Chromium in Ubuntu are usually installed with snaps. But snaps were not working, and I had disabled them above because of spamming the logs.
Snaps didn’t work for me in VNC. Here is how I installed firefox.
1sudo snap remove firefox
2sudo add-apt-repository ppa:mozillateam/ppa -y
3echo -e 'Package: *\nPin: release o=LP-PPA-mozillateam\nPin-Priority: 1001' | sudo tee /etc/apt/preferences.d/mozilla-firefox
4echo -e 'Package: firefox*\nPin: version 1:1snap*\nPin-Priority: -1' | sudo tee /etc/apt/preferences.d/mozilla-firefox-snap
5sudo apt update
6sudo apt install firefox -y
This might work for chromium. Didn’t try.
1sudo snap remove chromium
2sudo apt install apt-transport-https software-properties-common wget -y
3echo 'deb http://deb.debian.org/debian bookworm main' | sudo tee /etc/apt/sources.list.d/debian-stable.list
4echo -e 'Package: *\nPin: release a=stable\nPin-Priority: 500' | sudo tee /etc/apt/preferences.d/chromium
5echo -e 'Package: chromium*\nPin: origin deb.debian.org\nPin-Priority: 700' | sudo tee -a /etc/apt/preferences.d/chromium
6sudo apt update
7sudo apt install chromium -y