How To Stop Linux From Sleeping

There are numerous scenarios where you might require your Linux system to keep running and prevent it from sleeping or hibernating. For instance, when downloading a large file, running a long process, or providing services in a network environment, interruptions due to your Linux system going to sleep can be quite frustrating. While Linux’s sleep mode is beneficial for power saving, there are occasions when you need to stop Linux from sleeping. This post outlines how to achieve this.

1. Disabling Sleep Mode via System Settings

If you’re using a graphical user interface (GUI) on Linux, you might want to use system settings to disable sleep. This method is widely applicable across different Linux distributions including Ubuntu, Fedora, and CentOS.

Go to the system settings, then head over to the power management section. You should find options to manage sleep or suspend activities. You can disable automatic sleep or set the sleep delay to a very long time.

2. Using Terminal Commands

When it comes to flexibility and control, nothing beats the Linux terminal. You can use terminal commands to tweak the power management settings and prevent the system from sleeping.

For instance, using the systemctl command, you can temporarily inhibit sleep with the following command:

systemctl mask

To undo the above settings, use the unmask option:

systemctl unmask

You can also set up your system to stay awake when the lid is closed using the following command:

sudo sed -i 's/#HandleLidSwitch=suspend/HandleLidSwitch=ignore/' /etc/systemd/logind.conf

3. Using Caffeine Application

Caffeine is a handy little application available in Linux to prevent your computer from going into sleep mode. To install Caffeine, use the following command in Ubuntu:

sudo apt-get install caffeine

Once installed, you can easily control whether your Linux system goes to sleep or stays awake from the system tray.


There you have it – a few ways to stop your Linux system from sleeping. Choose the one that suits your needs and level of comfort with Linux. Remember, while it can be helpful to prevent your Linux from sleeping in certain situations, the sleep mode is a power-saving feature that should be enabled when not needed.