16

I've been at trying to do this for the last several hours with no progress.

I'm running Ubuntu 16.04 and I want to disable the sleep/suspend at the login screen (before logging in with any user) so that the display stays active. The suspension/sleep starts after 5 minutes -- a setting I can't seem to find anywhere.

Things that I've tried:

GUI

Done for both (all) users:

  • Never suspend under Power
  • Never turn screen off under Brightness and Lock.

Terminal

gsettings set org.gnome.desktop.session idle-delay 0
sudo /bin/systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
xset s noblank
xset s off
xset dpms force off
xset -dpms

crontab -e:

added

@reboot sudo /bin/systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
@reboot /usr/bin/xset s noblank
@reboot /usr/bin/xset s off
@reboot /usr/bin/xset dpms force off
@reboot /usr/bin/xset -dpms

dconf org.gnome.settings-daemon.plugins.power

critical-battery-action nothing
idle-dim false
lid-close-ac-action nothing
lid-close-battery-action nothing
sleep-inactive-ac-timeout 0
sleep-inactive-ac-type nothing
sleep-inactive-battery-timeout 0
sleep-inactive-battery-type nothing
time-critical 36000
time-low 36000

(The computer has neither lid nor battery btw)

sudo gedit /etc/X11/xorg.conf

Added

Section "ServerFlags"
  Option "BlankTime" "0"
  Option "StandbyTime" "0"
  Option "SuspendTime" "0"
  Option "OffTime" "0"
EndSection

Caffeine

Added

@reboot /usr/bin/caffeine &

in crontab. Also thought about doing the same with

@reboot /usr/bin/caffeine -t 36000

but

caffeine -t 36000

returns

usage: caffeinate [-h] [-V] COMMAND [ARGUMENT [ARGUMENT ...]]
caffeinate: error: unrecognized arguments: -t

acpi

Don't have it.

Any help would be much appreciated!

2

3 Answers 3

8

I had the same issue and found the solution in this forum thread. Setting the appropriate value using gsettings worked for me. Note that this needs to be set for the lightdm user, not for your own account or for root. Maybe this was your problem?

Here are the commands you need to run:

sudo su
su lightdm -s /bin/bash
dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0
exit
exit

Note that this only disables sleep for the machine when on AC power. Since I am using a desktop machine, this was sufficient. If you also want to disable sleeping when on battery power, you also need to set the sleep-inactive-battery-timeout value to 0.

After your have run these commands, restart LightDM and you should be good to go.

sudo service lightdm restart
2
  • 2
    If there is a No protocol specified error, then execute export DISPLAY= before running the dbus-launch gsettings command.
    – mxmlnkn
    Jan 1, 2022 at 14:21
  • Confirming that this still works, for Ubuntu 20.04 at least. I tried literally everything else, but never thought to try switching to the lightdm user. That did the trick. Thanks! Jan 18 at 21:16
6

I found a solution from here https://askubuntu.com/a/543861/718511, though they wanted to do the reverse so it's slightly modified. Essentially a script is made to disable dpms and lightdm told to run it.

In /etc/lightdm/lightdm.conf.d/ make a file 50-dpms.conf:

sudo nano /etc/lightdm/lightdm.conf.d/50-dpms.conf

Add the lines

[SeatDefaults]
display-setup-script=/usr/local/bin/dpms-stop

Close the file

In /usr/local/bin/ create a file dpms-stop:

sudo nano /usr/local/bin/dpms-stop

Add the lines

#!/bin/sh
sudo xhost +si:localuser:lightdm # grants localuser rights to X session
sudo su lightdm -s /bin/bash <<HERE
/usr/bin/xset -dpms
exit
HERE

Close the file

Make the file executable:

sudo chmod +x /usr/local/bin/dpms-stop

At reboot it worked for me.

1
  • This indeed works. Great job! Howver, on most machines you reallyneeds to modify screensaver to: '''/usr/bin/xset s off''' ; thus I upvoted Costa's answer from Jul 21 at 7:10 too.
    – judovana
    Aug 22, 2019 at 19:51
4

The only thing that worked for me was JohanPI's answer, but I had to modify it to turn off the screen saver as well. The modified script looks like this:

#!/bin/sh
sudo xhost +si:localuser:lightdm # grants localuser rights to X session
sudo su lightdm -s /bin/bash <<HERE
/usr/bin/xset -dpms
/usr/bin/xset s off
exit
HERE

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .