How to Stop Ubuntu from Automatically Suspending the CPU

The Sleeping Server

If you are running Ubuntu on a laptop or using a desktop as a headless home server, you might encounter a situation where the machine becomes completely unresponsive over the network after a period of inactivity. It stops responding to SSH requests, web services go offline, and scheduled cron jobs fail to run. This happens because Ubuntu is aggressively entering a deep ACPI sleep state (suspending the CPU to RAM) to conserve power when it believes the system is idle. While perfect for a laptop in a backpack, this automatic suspension is disastrous for any machine expected to provide continuous background services.

Disabling Automatic CPU Suspend

To ensure your machine remains awake and responsive at all times and stop Ubuntu from automatically suspending the CPU and entering sleep mode, you must disable the systemd sleep targets.

The most robust way to do this, regardless of your desktop environment (GNOME, server edition, etc.), is via the terminal using `systemctl`. Open a terminal window (Ctrl+Alt+T or via SSH). You need to mask the sleep, suspend, hibernate, and hybrid-sleep targets so the operating system literally cannot trigger them. Execute the following command exactly: sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target. Press Enter and provide your administrator password. You should see a confirmation that symbolic links were created pointing those targets to `/dev/null`. If you ever need to re-enable sleep functionality (for example, if you repurpose the server back into a daily-driver laptop), you can reverse this by running: sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.