The Unwanted Hibernation
By default, Ubuntu Linux is configured with relatively aggressive power-saving settings, especially when installed on a laptop. If you leave your computer unattended for a set period of time (often 15 or 20 minutes), the operating system will automatically suspend the session and put the computer to sleep. While this is great for conserving battery life, it is extremely problematic if you are using Ubuntu as a headless home server, running a long compilation script, downloading a massive file, or hosting a local network service. Having your machine unexpectedly go to sleep cuts off network connections and halts background processes, forcing you to constantly wiggle the mouse to keep it awake.
How to Disable Automatic Suspend in the GUI
If you are using the standard Ubuntu desktop environment (GNOME), you can easily disable the automatic sleep timer directly from the graphical settings menu.
1. Open the Settings application (click the system menu in the top-right corner of the screen and click the gear icon).
2. In the left-hand navigation sidebar, click on Power.
3. Scroll down the Power menu until you locate the section labelled Suspend & Power Button.
4. Click on the row labelled Automatic Suspend.
5. A dialog box will appear with separate settings for “Plugged In” and “On Battery Power” (if you are on a laptop).
6. Toggle the switches for both options to the Off position.
7. Close the Settings window.
Your Ubuntu machine will now remain fully awake and operational indefinitely, regardless of how long the keyboard and mouse remain idle.
How to Disable Automatic Suspend via the Terminal
If you are managing an Ubuntu server via SSH without a graphical interface, you can disable the system-wide suspend and hibernation targets using `systemctl`. This ensures the system cannot be put to sleep by the idle timer or even by accidental power button presses.
1. Open your terminal.
2. Run the following command to mask (completely disable) the sleep, suspend, hibernate, and hybrid-sleep targets in systemd:
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
3. The system will output confirmations that symlinks have been created pointing to `/dev/null`, effectively neutralizing the commands.
If you ever need to re-enable the ability to sleep in the future, simply run the reverse command:
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target