How to Completely Disable Suspend/Hibernate in Ubuntu 24.04 | 22.04

Last updated: October 8, 2024 — 4 Comments

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!

image from pixabay.com

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

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via ubuntuhandbook1@gmail.com Buy me a coffee: https://ko-fi.com/ubuntuhandbook1 |

4 responses to How to Completely Disable Suspend/Hibernate in Ubuntu 24.04 | 22.04

  1. Nice !
    Is “turning off screen without shutdown computer” still working after that ?
    Also, what happen if I close lid on laptop ?

    • Of course, it can automatically dim and turn off screen when idle. And, laptop lid close will do nothing, but only turn off the screen.

      • Speaking of that, is it possible to have it dim and turn off the screen when idle but still send some kind of “keep alive” signal to the display, so it doesn’t think it has lost its HDMI connection and put up a box complaining about that?

  2. This is a really great article. Thank you for sharing. Other old stackoverflow guides gave silly advice like deleting symlinks etc.

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

*