The Interrupted Server
If you are running Ubuntu Linux on a laptop that you use as a makeshift home server, or on a desktop that handles long-running tasks like compiling large codebases or rendering 3D animations, you cannot afford for the machine to take a nap. By default, Ubuntu is configured for personal desktop use and will automatically suspend itself (enter sleep mode) after a period of inactivity to save power. This instantly kills any active SSH connections and pauses all background processing.
How to Disable Automatic Suspend via GUI
If you are using the standard Ubuntu desktop interface (GNOME), you can disable sleep mode directly from the system settings.
1. Click the system menu in the top-right corner of the screen (where the battery and network icons are).
2. Select Settings from the drop-down menu.
3. In the left-hand sidebar, click on Power.
4. Look for the section labelled “Power Saving Options.”
5. Click on the row labelled Automatic Suspend.
6. A small dialog box will appear. You will see toggle switches for “On Battery Power” and “Plugged In.”
7. Turn both toggles to the Off position.
Your Ubuntu machine will now stay awake indefinitely, although it may still blank or lock the screen (which you can disable under Settings > Privacy > Screen).
How to Mask the Sleep Target via Systemd (Terminal)
If you are running an Ubuntu Server without a graphical interface, or if you want an absolute, unbreakable guarantee that the system will never sleep regardless of user settings, you must disable the sleep targets at the kernel level using `systemctl`.
1. Open your terminal application or SSH into your server.
2. Execute the following command to completely disable the suspend, hibernate, and sleep targets:
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
3. The terminal will confirm that these services have been linked to `/dev/null`, meaning any attempt by the operating system or an application to trigger sleep mode will simply vanish into the void.
If you ever need to restore the ability to sleep in the future, simply run the reverse command: sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target.