🔍 See Original Answer on Ask Ubuntu 🔗
Prevent sleep/suspend when not logged in to a specific account
April 8, 2019
Edited: June 12, 2020
November 24, 2022
Copy to clipboard: false
When no user is signed on
When no user is signed on the power settings come from psuedo-user ID
gdm. The following controls for GDM auto-suspend come from: ArchLinux GDM
GDM auto-suspend (GNOME 3.28)
GDM uses a separate dconf database to control power management. You can make GDM behave the same way as user sessions by copying the user settings to GDM’s dconf database.
$ IFS=$'\n'; for x in $(sudo -u username gsettings list-recursively org.gnome.settings-daemon.plugins.power); do eval "sudo -u gdm dbus-launch gsettings set $x"; done; unset IFS
username is your user’s name.
Or to simply disable auto-suspend (also run the command with ac replaced with battery to also disable it while running on battery):
$ sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'