Recently I’ve been logged into a laptop remotely a lot. Logging out from “main” session makes my Gnome on Debian 12 go to suspend after a while. To avoid it you just have to tell:
sudo dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
Thanks to WinEunuuchs2Unix for the answer I took from Prevent sleep/suspend when not logged in to a specific account; the only change is that GDM on Debian runs as root.
See also https://wiki.debian.org/Suspend#Disable_suspend_and_hibernation:
For systems which should never attempt any type of suspension, these targets can be disabled at the systemd level with the following:
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.targetTo re-enable hibernate and suspend use the following command:
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.targetA modern alternative approach for disabling suspend and hibernation is to create /etc/systemd/sleep.conf.d/nosuspend.conf as
[Sleep] AllowSuspend=no AllowHibernation=no AllowSuspendThenHibernate=no AllowHybridSleep=noThe above technique works on Debian 10 Buster and newer. See systemd-sleep.conf(5) for details.
If you just want to prevent suspending when the lid is closed you can set the following options in /etc/systemd/logind.conf:
[Login] HandleLidSwitch=ignore HandleLidSwitchDocked=ignoreThen run systemctl restart systemd-logind.service or reboot.