This tutorial shows how to completely disable suspend and/or hibernate function, so your Linux computer will never go to sleep.
Linux can automatically go to sleep when system is idle or laptop lid is closed, though user can configure to disable that behavior via either graphical options or logind.conf
configuration file.
But, if you never want to sleep your computer, e.g., for server, then you can completely disable this function. So even the suspend option in power-off menu or the corresponding Linux command won’t work!
Configure Systemd to Completely Disable System Sleep
For modern Linux distributions (e.g., Ubuntu, Debian, Fedora, Arch, and openSUSE) suspend, hibernate, and other sleep functions are managed by systemd.
Systemd includes following 4 services that perform the actions when user or system try going to sleep:
systemd-suspend.service
systemd-suspend-then-hibernate.service
systemd-hibernate.service
systemd-hybrid-sleep.service
Disable (mask) the services above won’t stop the actions, instead it breaks the sleep process. In my case, after masking suspend service in Ubuntu, it still can suspend my laptop, though it wakes up automatically few seconds later.
The correct way is to configure the systemd-sleep.conf
and write rules to tell systemd to disable the functions.
1. First, open terminal (Ctrl+Alt+T) or connect to your Linux server, then run command to edit the systemd sleep configuration file:
sudo nano /etc/systemd/sleep.conf
Here I use nano
command line text editor that works in both desktop and server. You may replace it with gedit
for Ubuntu 22.04 & earlier, gnome-text-editor
for 24.04 & other Linux with recent GNOME, mousepad
for XFCE, or other text editor depends on your desktop.
2. When file opens, scroll down and set following rules under [Sleep] section:
AllowSuspend=no AllowHibernation=no AllowSuspendThenHibernate=no AllowHybridSleep=no
Remove “#” at the beginning of the lines above if they exist and set value to no, or just add them manually. When done, press Ctrl+S to save changes and Ctrl+X to exit.
3. After saving the file, the ‘Suspend’ option disappeared immediately from the top-right power-off menu in my Ubuntu 24.04.
And, systemctl suspend
command refused to function and said ‘Call to Suspend failed: Sleep verb ‘suspend’ is disabled by config’.
NOTE: Systemd also read configurations from .conf
files under /etc/systemd/sleep.conf.d
directory. Meaning, you may run the command below instead to create a custom conf file:
sudo nano /etc/systemd/sleep.conf.d/disable-sleep.conf
Then, add the lines below into the file to either do the same job or even override the previous rules in step 2.
[Sleep] AllowSuspend=no AllowHibernation=no AllowHybridSleep=no AllowSuspendThenHibernate=no
Re-enable Suspend/Hibernate
To re-enable the functions, either re-configure the /etc/systemd/sleep.conf
file and comment out (add # at beginning) the 4 lines.
Or, just delete the file you added, for example ‘disable-sleep.conf’, under /etc/systemd/sleep.conf.d
directory.
sudo rm /etc/systemd/sleep.conf.d/disable-sleep.conf