How to completely disable sleep on Ubuntu 22.04 Desktop

If you use Ubuntu 22.04 Desktop version on your server, you need to make it awake all the time or it will be asleep and you cannot neither ping or ssh it, let alone RDP. So let’s do something to disallow our system to sleep.

Maybe you want to mention that we can change power saving settings to do it as below.

Screenshot 2024-07-27 at 17.58.10

However, I have tried it. If your server reboot and has nobody to login, it would still be asleep after some time(maybe 20 mins). So we still need to use command line to solve issues.

How to disable auto sleep

First of all, turn off auto sleep in GUI shown as before.

Then log into your server as root.

1
2
3
4
5
6
apt install dbus-x11
sudo -u lightdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0
sudo -u lightdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
sudo -u lightdm dbus-launch gsettings set com.canonical.unity.settings-daemon.plugins.power sleep-inactive-ac-timeout 0
sudo -u lightdm dbus-launch gsettings set com.canonical.unity.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
service lightdm restart

Reference

  1. https://blog.csdn.net/qq_29103181/article/details/139408264
  2. https://unix.stackexchange.com/questions/714803/ubuntu-22-04-is-sleeping-even-though-i-changed-the-power-settings-so-it-shouldn
  3. https://askubuntu.com/questions/1462727/completely-disable-sleep-on-ubuntu-22-04
  4. https://utcc.utoronto.ca/~cks/space/blog/linux/Ubuntu2204DesktopStopSuspend
  5. https://zhuanlan.zhihu.com/p/415661679
  6. https://askubuntu.com/questions/1337649/how-to-disable-suspend-in-20-minutes-from-the-lightdm-login-screen
  7. https://askubuntu.com/questions/942366/how-to-disable-sleep-suspend-at-login-screen