Linux Never Sleeps: Always Vigilant, Always Running

don

Linux users may find it frustrating when their system automatically goes into sleep mode, requiring them to push the power button and enter their password again to regain access. This is due to default power-saving settings in Linux distributions such as Ubuntu and can be easily changed.

To prevent a Linux system from going into sleep mode, users can adjust the power settings. This can be done by pressing the Super key (Windows key) and searching for settings, then navigating to Power settings. Here, users can change the screen blank settings and disable screen dimming entirely. Additionally, users can turn off the Automatic Suspend setting or change its time interval.

Another way to prevent sleep mode is by using the Caffeine app, which can be installed via the software center or the terminal. Once installed, users can start the Caffeine Indicator and enable the app, which will prevent the system from sleeping as long as it is active.

For Linux users who want to keep their laptop lid closed while connected to external monitors, additional steps are required. By editing the /etc/systemd/logind.conf file and changing the HandleLidSwitch setting, users can specify what action they want the system to take when the lid is closed, such as powering off, hibernating, suspending, or doing nothing.

By following these steps, Linux users can prevent their system from automatically going into sleep mode and avoid the frustration of having to repeatedly enter their password.

Characteristics Values
Operating System Ubuntu, Red Hat Linux 7, Debian
Default Power Saving Settings Screen lock after 5 minutes of inactivity
Power Settings Power Saving Options, Screen Blank Settings, Automatic Suspend
Caffeine App Caffeine Indicator, prevents system from sleeping
Lid Power Settings HandleLidSwitch=poweroff, HandleLidSwitch=hibernate, HandleLidSwitch=suspend, HandleLidSwitch=ignore
Suspend Modes Suspend to RAM, Suspend to Disk, Suspend to Both
Suspend Commands sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Verify Commands sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
Enable Suspend and Hibernation Commands sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

shunsleep

Preventing automatic sleep

To prevent your Linux system from automatically going into sleep mode, you can try the following methods:

Using Command Line:

  • Open a Terminal with administrative privileges.
  • Run the following command to disable the systemd targets responsible for sleep and hibernation:

```

$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

```

  • Reboot your system for the changes to take effect.
  • To verify if the changes were successful, use the following command:

```

$ sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target

```

To prevent the system from going into a suspend state when the laptop lid is closed, edit the `/etc/systemd/logind.conf` file by appending the following lines:

```

[Login]

HandleLidSwitch=ignore

HandleLidSwitchDocked=ignore

```

Save and exit the file, then reboot for the changes to take effect.

Using GUI Settings:

  • Press the Super key (Windows key) and search for "Settings".
  • Go to "Power Settings" and adjust the "Power Saving Options" to your preference.
  • You can change the screen blank settings from the default 5 minutes to up to 15 minutes, or disable screen dimming entirely by choosing "Never".
  • Change the "Automatic Suspend" setting to turn it off completely or adjust the time interval.

Using Caffeine App:

Install the Caffeine app from the software center or by using the following command in the terminal:

```

Sudo apt install caffeine

```

  • Search for "Caffeine Indicator" in the activity area (press the Windows key and type "caffeine").
  • Start the Caffeine Indicator and click on the coffee icon in the top panel to enable it.
  • Your system will now remain active as long as Caffeine is enabled.

Using GRUB Configuration:

  • Edit the GRUB configuration file (`/etc/default/grub`) and add the following options to the `GRUB_CMDLINE_LINUX_DEFAULT` line: acpi=off apm=off.
  • Run `sudo update-grub` and reboot your system for the changes to take effect.

Please note that some of these methods may have different effects on different Linux distributions and configurations. Always test the changes in a controlled environment before applying them to production systems.

The Book That Keeps You Up All Night

You may want to see also

shunsleep

Disabling screen locking

Ubuntu:

On Ubuntu, you can disable screen locking by following these steps:

  • Open the Settings menu by clicking on the gear icon in the top-right corner of your screen.
  • Select Brightness and Lock from the settings menu.
  • Set the "Turn screen off when inactive" option to "Never".
  • Alternatively, you can use the "gsettings" command in a terminal to disable screen locking. Run the command: "gsettings set org.gnome.desktop.session idle-delay 0" to disable the screen from turning off.
  • If you want to enable the screen to turn off after a certain delay, you can use the command: "gsettings set org.gnome.desktop.session idle-delay" followed by the desired delay time in seconds. For example, to set a 5-minute delay, use: "gsettings set org.gnome.desktop.session idle-delay 300".
  • Another method is to open the Power settings by clicking on the power button in the top-right corner of your screen. Then, select "Never" from the "Blank Screen" drop-down menu.
  • Additionally, you can install applications like "caffeine" and "caffeine-indicator" from the Ubuntu app store to manage screen locking.

GNOME:

If you're using the GNOME desktop environment, you can prevent the screen from locking and turning off by using the "gnome-shell-extension-unblank" extension. This extension allows you to lock your screen without putting the system to sleep. You can also try pressing "Super+L" instead of "Super+Esc" to lock your screen without triggering sleep mode.

Debian:

On a Debian system with the GNOME desktop, you can configure the system to turn off the display immediately after locking the screen. Here's how:

  • Open a terminal and run the following command to create a new script: "sudo nano /path/to/your/script.sh".
  • Add the following lines to the script: "gnome-screensaver-command --lock" and "xset dpms force off".
  • Save and close the script file.
  • Make the script executable by running the command: "sudo chmod +x /path/to/your/script.sh".
  • Now, you can bind this script to a key sequence of your choice. For example, you can change the "Lock" keyboard shortcut to run this script instead.

Red Hat Linux:

To disable sleep and configure lid power settings on Red Hat Linux 7, follow these steps:

  • Open a Terminal by pressing Ctrl + Alt + T or by navigating to Applications > Utilities > Terminal.
  • Run the following commands to disable sleep: "# systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target" and "# systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target".
  • To configure lid power settings, open the "/etc/systemd/logind.conf" file for editing.
  • Find the line "#HandleLidSwitch=suspend" and remove the "#" character at the beginning of the line.
  • Change the line to one of the desired settings: "HandleLidSwitch=poweroff" to shut down the computer when the lid is closed, "HandleLidSwitch=hibernate" to hibernate, "HandleLidSwitch=suspend" to suspend, or "HandleLidSwitch=ignore" to do nothing when the lid is closed.
  • Save the file and restart the systemd-logind service by running the command: "# systemctl restart systemd-logind".

shunsleep

Using the Caffeine app

Caffeine is a free and open-source tool that prevents your Linux system from going to sleep. It is a simple solution with minimal settings, allowing you to control when and how long your system stays awake.

Installation

Caffeine is available in the default Ubuntu repository. To install it, open the Software app and search for "Caffeine". Click on the app and then on "Install".

Alternatively, you can use the command line by opening the Terminal app (Ctrl + Alt + T) and entering the following commands:

Sudo apt update

Sudo apt install caffeine

Activation

Once installed, search for "Caffeine Indicator" in your applications. This will place a coffee cup icon in your system tray. Click on the empty cup and select "Activate" to enable Caffeine.

To disable Caffeine, simply click on the full cup icon and select "Deactivate".

Customisation

By default, Caffeine is not available in the system tray after each boot-up. To change this, add Caffeine Indicator to your Startup Applications Preferences.

You can also manually edit the rules for when Caffeine activates, or use Caffeine Indicator to toggle it on and off.

shunsleep

Editing the /etc/systemd/logind.conf file

To prevent your Linux system from going to sleep, you can edit the `/etc/systemd/logind.conf` file. Here are the steps you can follow:

  • Open a Terminal: You can do this by pressing the Ctrl + Alt + T keyboard shortcut or by going to the Applications menu, selecting Utilities, and then Terminal.
  • Run the Following Commands:
  • # systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
  • # systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
  • Configure Lid Power Settings: Open the `/etc/systemd/logind.conf` file in a text editor with root privileges.
  • Modify HandleLidSwitch: Find the line `#HandleLidSwitch=suspend` and remove the `#` at the beginning of the line. Change this line to one of the following options:
  • HandleLidSwitch=poweroff to shut down the computer when the lid is closed.
  • HandleLidSwitch=hibernate to hibernate the computer when the lid is closed.
  • HandleLidSwitch=suspend to suspend the computer when the lid is closed.
  • HandleLidSwitch=ignore to do nothing when the lid is closed.
  • Save and Restart the Service: Save the changes to the `/etc/systemd/logind.conf` file and restart the systemd-logind service to apply the changes by running the command `# systemctl restart systemd-logind`.
  • Check for Typos: Ensure that there are no typos in the `logind.conf` file, as this can cause issues with parsing the file correctly.
  • Check for Symlinks: If the /etc/systemd/logind.conf file is a symlink, copy the original file instead of using a symlink.
  • Reload Instead of Restart: Instead of restarting the systemd-logind daemon, you can simply reload it with the command `sudo systemctl reload systemd-logind`.
  • Modify RemoveIPC (for RHEL 7.X): If you are using Red Hat Enterprise Linux (RHEL) 7.X, navigate to the `/etc/systemd` directory and open the `logind.conf` file for editing. Find the RemoveIPC line and ensure it is set to `no`. Remove the `#` if present and change `yes` to `no` if necessary.

By following these steps, you can edit the `/etc/systemd/logind.conf` file to prevent your Linux system from going to sleep or taking specific actions when the laptop lid is closed.

shunsleep

Disabling suspend with systemctl

To disable suspend with systemctl, you can use the following commands:

Sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

This command will prevent your system from suspending, sleeping, hibernating, or entering hybrid sleep. You can verify that these daemons are disabled by running the following command:

Sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target

If you ever need to re-enable suspend and hibernation, you can do so by using the following command:

Sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

Additionally, if you are using a laptop, you may also want to configure the lid power settings. This can be done by editing the `/etc/systemd/logind.conf` file and changing the `HandleLidSwitch` option to one of the following:

  • `poweroff`: Shutdown the computer when the lid is closed.
  • `hibernate`: Hibernate the computer when the lid is closed.
  • `suspend`: Suspend the computer when the lid is closed.
  • `ignore`: Do nothing when the lid is closed.

Remember to save the file and restart the systemd-logind service or reboot your system for the changes to take effect.

Frequently asked questions

You can disable sleep mode on your Linux system by changing your power settings. On Ubuntu, you can do this by going to Power Settings and changing the screen blank settings to a higher value or selecting 'Never'.

To prevent your Linux system from locking automatically, you can change the automatic suspend settings. On Ubuntu, go to Power Settings and change the Automatic Suspend settings.

To prevent your Linux system from sleeping when you close the laptop lid, you can configure the lid power settings. On Ubuntu, open the /etc/systemd/logind.conf file and change the HandleLidSwitch setting to 'ignore'.

To prevent your Linux system from putting your monitor to sleep, you can change the power management settings. On Ubuntu, go to Preferences > Power Management and change the settings to never put the computer or display to sleep.

Written by
Reviewed by
Share this post
Print
Did this article help you?

Leave a comment