← BACK TO GUIDES

Sunshine on a Headless Kubuntu VM

A headless Sunshine setup built correctly the first time: KMS capture, GPU permissions, a proper systemd unit, working PipeWire audio, and a desktop that survives being idle.

#STREAMING#NVIDIA
This is how I set up a headless Kubuntu 26 VM with an NVIDIA GPU passed through. The stock install, the stock user service, and a default desktop session all assume someone is sitting at the machine, so each of those assumptions is fixed here before Sunshine ever starts. Every step below prevents a problem I hit the hard way, and doing them in this order means one reboot and no debugging.

Step 1: Prepare Kubuntu and the GPU

Point APT at the University of Waterloo mirror first so the driver download is quick:
sudo sed -i.bak -E '/^URIs:/c\URIs: http://mirror.csclub.uwaterloo.ca/ubuntu/' /etc/apt/sources.list.d/ubuntu.sources && sudo apt update
Install the recommended NVIDIA driver. Kubuntu ships these signed, so there is no MOK enrollment step. Do not reboot yet; the next few commands ride along with the same reboot.
sudo apt update && sudo ubuntu-drivers install
Add the account that will run Sunshine to the GPU groups now. Without this, KMS capture fails later with /dev/dri/card1: Permission denied.
sudo usermod -aG video,render virt
Turn on NVIDIA DRM modesetting. KMS capture cannot work without it, and the failure it causes is easy to misread as a permissions problem. Open /etc/default/grub and append both parameters to GRUB_CMDLINE_LINUX_DEFAULT:
sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nvidia-drm.modeset=1 nvidia-drm.fbdev=1"
Then apply the change:
sudo update-grub
Configure SDDM to log the user in automatically. A headless VM has nobody to type a password, and without autologin Sunshine only ever sees the login screen. Create the drop-in:
sudo nano /etc/sddm.conf.d/autologin.conf
Paste this into the file and save:
[Autologin] User=virt Session=plasma.desktop Relogin=false
Session=plasma.desktop selects KDE Plasma, and Relogin=false keeps it from logging straight back in after a manual logout. Now reboot once. The driver, kernel parameters, group membership, and autologin all take effect together:
sudo reboot
When it comes back, confirm the two things that break KMS capture later:
cat /proc/cmdline id virt
The first should list nvidia-drm.modeset=1 and nvidia-drm.fbdev=1. The second should list video and render. You should also land directly on the Plasma desktop.

Step 2: Stop the desktop from going idle

A headless VM has no local keyboard or mouse, so KDE considers it idle and blanks the screen. Once the display blanks, KMS capture stops and Moonlight fails with error 503. Turn this off before you stream. In Plasma, open System Settings and set Power Management → Energy Saving to Never for both dimming and screen energy saving, then turn off automatic screen locking under Security & Privacy. From a terminal inside the session you can also disable X11 blanking:
xset s off xset -dpms

Step 3: Install and configure Sunshine

This configures the Cloudsmith stable repository and installs Sunshine:
curl -1sLf 'https://dl.cloudsmith.io/public/lizardbyte/stable/cfg/setup/bash.deb.sh' | sudo -E bash && sudo apt update && sudo apt install -y sunshine
Write the capture settings now, before the first start, so Sunshine never wastes a run trying a session capture it cannot get, and never tries to build a tray icon that will crash it. Create the config:
mkdir -p ~/.config/sunshine && nano ~/.config/sunshine/sunshine.conf
Paste these three lines and save:
capture = kms adapter_name = /dev/dri/renderD128 system_tray = disabled
capture = kms reads frames straight from the GPU framebuffer, which is what a machine with no Wayland or X session can actually use. adapter_name pins the render node. system_tray = disabled matters because the tray failure otherwise takes the whole main loop down on a headless host.

Step 4: Create the systemd service properly

The Cloudsmith package does not create a unit. A user service is the wrong shape here on two counts: it starts with a user session that does not exist, and it cannot hold the ambient capabilities that KMS capture needs. This one-liner writes a system service with the right user, HOME, the session runtime directory and PipeWire socket that audio needs, and the KMS capabilities, then enables and starts it:
u="$USER"; h="$(getent passwd "$u" | cut -d: -f6)"; i="$(id -u "$u")"; printf '[Unit]\nDescription=Sunshine game streaming host (KMS)\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\nUser=%s\nEnvironment=HOME=%s\nEnvironment=XDG_RUNTIME_DIR=/run/user/%s\nEnvironment=PULSE_SERVER=unix:/run/user/%s/pulse/native\nAmbientCapabilities=CAP_SYS_ADMIN CAP_SYS_NICE\nExecStart=/usr/bin/sunshine\nRestart=on-failure\nRestartSec=5s\n\n[Install]\nWantedBy=multi-user.target\n' "$u" "$h" "$i" "$i" | sudo tee /etc/systemd/system/sunshine.service >/dev/null && sudo systemctl daemon-reload && sudo systemctl enable --now sunshine.service
Check that it started and watch it initialize:
systemctl status sunshine.service sudo journalctl -u sunshine.service -f
KMS capture should come up and the NVENC encoder should follow, with no CAP_SYS_ADMIN or Permission denied lines.
If the log still reports Failed to gain CAP_SYS_ADMIN, the capability is not surviving the service. Set it on the binary instead and remove the AmbientCapabilities line from the unit:
sudo setcap cap_sys_admin,cap_sys_nice+p $(readlink -f $(which sunshine))
sudo systemctl daemon-reload && sudo systemctl restart sunshine.service

Step 5: Route audio through PipeWire

Video can be flowing while audio stays silent, with Couldn't connect to pulseaudio: Access denied in the log. The service already runs as virt, so this is not a run-as-root problem. A system service starts outside the user session, so it has no XDG_RUNTIME_DIR and no way to find the PipeWire socket. The two Environment lines in the unit created in Step 4 are what solve it, and this is what they do.
The unit as /etc/systemd/system/sunshine.service should look like this:
[Unit] Description=Sunshine Game Streaming Host (KMS) StartLimitIntervalSec=500 StartLimitBurst=5 After=network-online.target [Service] User=virt Environment=HOME=/home/virt # Add the next two lines: Environment=XDG_RUNTIME_DIR=/run/user/1000 Environment=PULSE_SERVER=unix:/run/user/1000/pulse/native ExecStart=/usr/bin/sunshine Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target
XDG_RUNTIME_DIR is the per-user runtime directory PipeWire and PulseAudio use, and PULSE_SERVER points straight at the compatibility socket so Sunshine does not have to guess it. Confirm your own UID with id -u virt and adjust the paths if it is not 1000. After editing the file, apply it:
sudo systemctl daemon-reload sudo systemctl restart sunshine

Point Sunshine at a monitor source

The socket gets Sunshine past the permission error, but PipeWire does not honor Sunshine's default @DEFAULT_MONITOR@ request, which shows up as silence or the wrong device. Find the monitor for the default sink:
pactl info | grep Source
That prints a name like alsa_output.pci-0000_00_1f.3.analog-stereo.monitor. Add it to ~/.config/sunshine/sunshine.conf:
audio_sink = alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
Use the exact name from your own output. If the default sink changes between boots, Sunshine's own virtual source is a stable fallback:
audio_sink = sink-sunshine-stereo.monitor
Restart Sunshine, reconnect from Moonlight, and confirm the access error is gone from the log:
sudo journalctl -u sunshine.service -f

Step 6: Reach the web UI over SSH

Sunshine's web UI listens on 47990. Forward that port from your local machine:
ssh -L 47990:localhost:47990 [email protected]
Then open https://localhost:47990 in your local browser and accept the certificate warning. The forward only exposes the web UI. If something later misbehaves, this is not the thing that broke.

Step 7: If it still misbehaves

With the setup above, these are the only failures left, and each has a one-line cause.
Address already in use on port 48010 means an older Sunshine process is still holding the port:
sudo fuser -k 48010/tcp
A blank login background and a cursor that will not move means SDDM autologin did not take. Check the drop-in is in /etc/sddm.conf.d/, that Session=plasma.desktop matches an installed session under /usr/share/xsessions/, and that SDDM restarted:
ls /usr/share/xsessions/ systemctl status sddm
Error 503 after a while means the session blanked. Revisit Step 2; there is no dummy plug involved in a KMS setup.
The same unit can work fine on another machine and fail here, which is what makes this confusing. A machine with an active session or a connected display captures through X11 or a Wayland portal. A headless VM has neither, so it has to use KMS with the capabilities, permissions, and display handling set up above.

Step 8: Optional desktop finishing

Set the global time format to 24-hour time with Plasma's native locale setting:
kwriteconfig6 --file plasma-localerc --group Formats --key LC_TIME en_GB.UTF-8
Log out and back in for that to apply across the panel, lock screen, and other Plasma surfaces.
Remove snapd and its packages, install Flatpak with Flathub, and install Brave from Flathub:
sudo apt purge -y snapd && sudo apt autoremove --purge -y && sudo apt install -y flatpak && sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo && sudo flatpak install --system -y flathub com.brave.Browser
Purging snapd removes the Snap packages it manages and their data. Back up anything you want to keep first.