Hello,
A server must be available 24 hours a day and obviously should not go to sleep, especially if we don’t have the tools to “wake it up.”
By default, or following the installation of certain packages, a Debian distribution may retain power-saving settings. The result: our machine “falls asleep” after a period of inactivity, and we can no longer access it remotely. 1
This is particularly true for systems installed in a Desktop version (i.e., with a desktop manager like GNOME or others).
It’s a bit stupid for a server, isn’t it?
Here is how to prevent sleep at the system level.
We will only use the command line. 2
Standard GUI configuration is not enough (and can be misleading)#
On Debian, power management is multi-layered.
Disabling sleep in a GUI or via a simple script isn’t always enough, as several services can trigger a suspend event:
systemd targets, which orchestrate the transition to sleep states.systemd-logind, which reacts to hardware events (power button, reset button, inactivity…).
For a production machine, we can mask the sleep tools to make them inaccessible even to the system itself.
Masking sleep services#
Rather than simply disabling the services associated with sleep, we mask them to prevent any access.
We use the mask command (instead of disable). It creates a symbolic link to /dev/null, making it impossible to activate the service, even if another process requests it.
To do this, we run: 3
| |
To confirm that the targets are indeed locked:
| |
Example output:
| |
Configuring systemd-logind#
Even if the targets are masked and thus inaccessible, we can configure the session manager (systemd-logind = login daemon) so that it doesn’t even try to interpret inactivity signals or physical buttons… Better safe than sorry.
We edit the configuration file:
| |
We modify and/or uncomment the following lines to force the ignore state:
| |
We restart the service to apply the changes:
| |
Analyzing logs#
Two commands can be useful for auditing the server logs:
To check systemd-logind events:
| |
For ACPI state changes at the kernel level:
| |
This command allows you to see if the kernel has actually prepared a transition to S3 (sleep to RAM) or S4 (hibernation).
Conclusion#
By combining the masking of systemd targets and the neutralization of actions in logind.conf, we eliminate any risk of accidental sleep on our Debian server. 4
This is a hardening step that is best taken BEFORE you find yourself in a mess.
Best regards,
Marc JESTIN
https://marcjestin.fr
Sleep is generally of the
ACPI S3type = the computer stays on standby to keep the RAM active in its current state for a much faster restart thanACPI S4. ↩︎In principle, you don’t install a graphical interface on a server, but it’s true that it can be convenient for
self-hosting. ↩︎All commands in this article require
rootprivileges. I am among those who do not recommend usingsudo. And I know why. ↩︎Provided, of course, that we have ensured no sleep settings are configured at the
UEFI(e.g.,BIOS) level on the machine. ↩︎