This is a guide on setting up a headless Sunshine game streaming server on Ubuntu server 22.04 with no physical display attached. For this guide you will need root or have sudo permissions.
First lets install the prerequisite packages.
- Install the ubuntu desktop meta package using
sudo apt-get install ubuntu-desktop
- Install the Nvidia driver and cuda tool kit using the instructions at this link.
- Download the Sunshine Ubuntu 22.04 release from here
- install it with this command
sudo apt install -f ./sunshine-ubuntu-22.04-amd64.deb
- reboot your system
Patching the Nvidia driver
Download the Nvidia driver patcher from here to patch in Nvidia frame buffer copy.
cd nvidia-patch
./patch-fbc.sh
Next lets configure the desktop environment.
- Start be editing the gdm config file to disable wayland and autolog in the user you want to access remotely.
vi /etc/gdm3/custom.conf
uncomment the WaylandEnable=false line
as well as these two lines. Replace user with the username of who you want to auto login
AutomaticLoginEnable = true
AutomaticLogin = user
- Switch to the home of the user you set to autologin and edit the pipewire config file to unload bluetooth driver, if you donât do this pipewire will fail to autostart and sunshine will crash when you try to connect as it will be unable to create an audio sink
vi ~/.config/pulse/default.pa to include
###unload driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
unload-module module-bluetooth-policy
.endif
.ifexists module-bluetooth-discover.so
unload-module module-bluetooth-discover
.endif
- Create an edid file to fake a connected display. This file should be in the user you set to autologin home directory.
A sample edid that supports up to 1080p60can be downloaded from here
- Setting up an Xorg config file
run nvidia-xconfig to create an Xorg config file
nvidia-xconfig
then edit it with
vi /etc/X11/xorg.conf
Replace the screen section with this, where edid path is the full path to the edid file.
Section âScreenâ
Identifier âScreen0â
Device âDevice0â
Monitor âMonitor0â
DefaultDepth 24
Option âAllowEmptyInitialConfigurationâ âTrueâ
Option âUseDisplayDeviceâ âDP-0â
Option âCustomEDIDâ âDP-0:Edid Pathâ
Option âConnectedMonitorâ âDP-0â
SubSection âDisplayâ
Depth 24
EndSubSection
EndSection
Next create a udev rule to allow sunshine to create input devices.
echo âKERNEL==âuinputâ, SUBSYSTEM==âmiscâ, OPTIONS+=âstatic_node=uinputâ, TAG+=âuaccessââ |
sudo tee /etc/udev/rules.d/85-sunshine.rules
Opening ports in the firewall
you need to open these ports to allow you to connect to sunshine
ufw allow 47984/tcp
ufw allow 47989/tcp
ufw allow 48010/tcp
ufw allow 47998/udp
ufw allow 47999/udp
ufw allow 48000/udp
ufw allow 48002/udp
ufw allow 48010/udp
Autostarting sunshine
First in the home directory of the user you have set to autologin youâll need to make the required directory for systemd user services
mkdir ./.config/systemd/user/
Next make the systemd service file. This file is set to start pulseaudio if its not running and only start sunshine after pulseaudio has started.
vi ./.config/systemd/user/Sunshine.service
[Unit]
Description=Sunshine is a self-hosted game stream host for Moonlight.
StartLimitIntervalSec=500
StartLimitBurst=5
Requires=pulseaudio.service
After=pulseaudio.service
[Service]
ExecStart=//usr/bin/sunshine
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=graphical-session.target
Reload the systemctl daemon so you can use the new service file you created.
systemctl --user daemon-reload
Set sunshine to start at boot
systemctl --user enable Sunshine.service
Set systemctl to start the graphical target, so the desktop environment is started on boot
systemctl set-default graphical.target
Now reboot your machine, sunshine should be up and running but it still needs to be configured. You can check its status with
systemctl --user status Sunshine
Configuring sunshine
The Sunshine docs cover this pretty well. Sunshines autoconfig should work fine, but you still need to access the webui for it to pair the client. The webui is only accessible from the host running sunshine on port 47990. You can access this port over ssh using port forwarding with
ssh -L 47990:localhost:47990 -C user@remotemachine
The go to https://localhost:47990/ and follow the set up directions.
Congrats Sunshine should now be installed and fully operational