100

I am runnning Ubuntu Server on my laptop. There is really no reason for the screen to be on. I have been trying to use this command to turn the screen off:

sleep 1 && xset dpms force off

The problem is I get the following error

unable to open display "".

Any idea what is going on / what is wrong? Any other suggestions for how to do this?

8
  • Do you have an X server installed? And it is running?
    – enzotib
    Sep 24 '11 at 20:55
  • 1
    Try running this first: export DISPLAY=:0.0
    – RobinJ
    Sep 24 '11 at 21:00
  • 1
    Maybe I'm missing something here, but doesn't the monitor have a power button? Sep 25 '11 at 1:06
  • 2
    @WarriorIng64: it is a laptop
    – enzotib
    Sep 25 '11 at 8:39
  • 1
    Ah, sorry...missed that part. Sep 25 '11 at 18:03

10 Answers 10

80

To turn off monitor in console, the command is the following:

sudo vbetool dpms off

To regain control of the console on pressing Enter key, I suggest

sudo sh -c 'vbetool dpms off; read ans; vbetool dpms on'
13
  • 3
    You probably then want to alias this lot to something handy. Sep 24 '11 at 21:33
  • 3
    vbetool is available via sudo apt-get install vbetool Mar 8 '14 at 6:21
  • 1
    In my case this command really turned the display off and not the xset one
    – golimar
    Feb 10 '17 at 16:58
  • 3
    Ubuntu 20.04 LTS: vbetool dpms off does not work and says mmap /dev/zero: Operation not permitted and then Failed to initialise LRMI (Linux Real-Mode Interface).. Tried on X11 as root and via ssh as root and on text console as root.
    – Tino
    Feb 9 '21 at 19:53
  • 1
    I confirm that this command doesn't work on Ubuntu server 20.04 @Tino
    – HXH
    Mar 13 '21 at 8:02
50

Try these commands...

To Turn Off:

xset -display :0.0 dpms force off 

To Turn On:

xset -display :0.0 dpms force on 

If your display turns off and then immediately back on then try the following which adds a delay of 1 second before turning the screen off. This give a chance for all events to be processed by the X server before turning the display off.

sleep 1 && xset -display :0.0 dpms force off 
5
  • How do I know which screen is which Jul 30 '17 at 15:26
  • 1
    The following worked for me (also partially inspired by @enzotib's answer): xset -display $DISPLAY dpms force off; read temp; xset -display $DISPLAY dpms force on Aug 4 '17 at 2:52
  • Be careful with this. I'm unable to turn my monitor back on with a test machine after issuing force off
    – Zmart
    Oct 31 '17 at 17:02
  • 3
    Update: Pulling out and replugging all cables (including power) on the monitor has remedied the situation.
    – Zmart
    Oct 31 '17 at 17:08
  • 1
    Ubuntu 20.04 LTS does not work: server does not have extension for dpms option. Blanking via keyboard shortcut (Fn+F6 in my case) works (a bit unreliable, releasing Fn often unblanks screen again). But I need a solution which works via ssh when the Laptop's keyboard is out of reach. (It's really annoying if you wake up in bed because the Laptop lights the room. Just a short voice command could invoke ssh to stop the Laptop burning! Note that I disable screensavers on consoles, as there is only one thing which is even more annoying than wrong time console blanking: CapsLock!)
    – Tino
    Feb 9 '21 at 18:51
42

The xset command mentioned in other answers will turn off all the monitors if you have multiple monitor setup. However if you want turn off only one or some of the monitor you should use xrandr.

First run xrandr -q command, which will list all the monitors and its current display settings. At the start of each monitor details you will find monitor name set by the system. You have to keep track of that.

I have two monitors (one is connected to DVI port and other to VGA port) and when I run the command I see this:

Screen 0: minimum 320 x 200, current 1360 x 768, maximum 2726 x 2726
DFP1 connected 1360x768+0+0 (normal left inverted right x axis y axis) 304mm x 228mm
   1360x768       59.7*+
   ... (more details are shown here, but I have hidden it)

CRT1 connected 1360x768+0+0 (normal left inverted right x axis y axis) 410mm x 230mm
   1360x768       59.8*+   60.0  
   ... (more details are shown here, but I have hidden it)

In this output, DVI port connected monitor is labelled as DFP1 and other one as CRT1. So if I want turn off the secondary monitor(i.e., CRT1) I have run this command:

xrandr --output CRT1 --off

if you want switch on that monitor again then you have run this command:

xrandr --output CRT1 --auto
8
  • I have 3 Monitors, 1 VGA, 1 DVI and 1 HDMI. When i ran: xrandr --output VGA1 --auto, it turned the VGA on, but it cloned the DVI monitor. Feb 23 '15 at 0:43
  • Hmm strange. Try --on instead of --auto Feb 23 '15 at 2:58
  • @HarshithJ.V. this is a good answer! Its better than the xset because xset turns on if you just press the touchpad etc. Btw hope you remember me from your previous company :-)
    – Nishant
    Nov 13 '16 at 18:05
  • @Nishant Thanks for compliments. Strangely I don't remember you. Please ping me on any other social media as we can't chat over as its against the rules. Apr 14 '17 at 5:00
  • 2
    thank you for your answer, I would only add that (as in the case of @ThiagoPonte) xrandr --output DP-5 --auto --right-of CRT1 allows to turn back on the monitor without cloning (replace --right-of with whatever your setup is) Jan 8 '20 at 8:41
29

I've just installed Ubuntu Server 18.04.1 (no GUI, X, nor anything graphical), and after breaking my back last night trying to turn off the screen I finally found the magic command:

setterm --blank 1

After executing the command the screen will turn off automatically every minute (if idle).


And even better, if you want the command to be executed automatically at boot, you can add it to the GRUB commandline, to do so we have to edit the next file:

sudo nano /etc/default/grub

Once there, just add consoleblank=60 to GRUB_CMDLINE_DEFAULT, it should look like this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet consoleblank=60"

Then close the file and save it, after that just run sudo update-grub and voila, every time you boot the screen will turn off automatically every 60 sec. (again, if idle).

And this way (adding the consoleblank to the GRUB) works even from remote terminals (ssh).

Enjoy! (again)

6
  • 1
    Executing the above command I get: "setterm: terminal xterm-256color does not support --blank". What can be wrong?
    – zx485
    Sep 19 '18 at 21:23
  • 1
    Are you trying from a remote session?
    – AxeAR
    Sep 20 '18 at 1:41
  • @zx485 Check out the updated answer, now you can make the screen turn off from a remote session. I'm sure this will solve your problem
    – AxeAR
    Jun 8 '19 at 20:34
  • Just what I was looking for! This is usually included by default in most distros but not server-centric ones like proxmox. Works like a charm.
    – pinkeen
    Apr 28 '20 at 16:57
  • 2
    Caution! The value passed to setterm --blank is minutes not seconds. I was scratching my head for a while until decided to read TFM.
    – pinkeen
    Apr 28 '20 at 17:25
9

Blank screen after 1 min and turn it off after 2 min. Any keypress will turn it back on. Make it auto-start after reboot.

The magic command what will do all the work:

setterm --blank 1 --powerdown 2

If you get error: setterm: terminal xterm-256color does not support --blank

  • You are probably trying this command by SSH. You must run it from local of your machine, or do next stage of this guide.

Make it auto-start

Insert command in executable file. Store it for example in hidden folder of your home directory /home/USER/.boot-scripts/screen-off.sh

#!/bin/bash
setterm --blank 1 --powerdown 2

And make script file executable by systemctl. Create file /etc/systemd/system/screen-off.service

[Unit]
Description=Blank screen after 1 min and turn it off after 2 min. Any keypress will turn it back on.
After=ssh.service

[Service]
Type=oneshot
Environment=TERM=linux
StandardOutput=tty
TTYPath=/dev/console
ExecStart=/home/USER/.boot-scripts/screen-off.sh

[Install]
WantedBy=local.target

Make it executable:

    sudo chmod +x /home/USER/.boot-scripts/screen-off.sh
    sudo chmod +x /etc/systemd/system/screen-off.service

And finally get it working and enabled on boot:

sudo systemctl start screen-off.service
sudo systemctl enable screen-off.service

To disable it:

sudo systemctl disable screen-off.service
6
  • Why does it need to start after ssh.service? Dec 15 '19 at 14:44
  • no effect on macbook pro
    – Drew
    Feb 5 '20 at 20:44
  • service works perfectly on Ubuntu Linux using systemd; thanks for the fantastic tutorial. This is great for a laptop server. Also @Drew this is "Ask Ubuntu" not "Ask Different" the instructions are for Linux not macOS.
    – cody.codes
    Jun 5 '20 at 6:21
  • I guess @Drew is running Ubuntu on his Macbook Pro... setterm --blank 1 --powerdown 2 doesn't seem to work on those machines.
    – TCB13
    Jun 17 '20 at 21:31
  • 1
    Lacking support for xset dpms, running chvt 2 && setsid sh -c 'TERM=linux setterm --blank force <>/dev/tty2' as root via ssh does the trick at my side. However chvt likes to crash X11 such, that, immediately, screen and keyboard and, not immediately, network connections become unavailable. I really have no good idea how Ubuntu 20.04 managed to archive this. Probably NetworkManager hangs in X11, so everything goes south when DHCP expires or something similar toggles something on the network. The machine definitively stays up, but is in it's own lonely Universe afterwards.
    – Tino
    Feb 9 '21 at 19:42
5

If you have multiple monitors use this:

Turning off your second monitor:
(Assuming CRT-0 is your left monitor and CRT-1 is your right monitor)
xrandr --output CRT-1 --off
Turning on your second monitor:
xrandr --output CRT-1 --right-of CRT-0 --auto
This way xrandr knows not to duplicate the first screen.

1
  • I was testing this, turning off a screen this way is more like disabling it, eg, the screen is still powered on. Its just not used. The --off'd screen cannot be turned back on with the screen's power button (because its still on / was never off). It also messed with my desktop display settings, (from extended desktop to mirrored displays). If this was done to turn both displays off, I'm not sure it would be easy to turn them back on without logging in to TTY and clearing the monitors.xml file wherever it is. The more you know. Dec 12 '16 at 18:02
3

@stiemannkj1's answer(inspired by @enzotib's answer) buried in the comments to @harshith-j-v's answer (works on my laptop connected to a monitor):

xset -display $DISPLAY dpms force off; read temp; xset -display $DISPLAY dpms force on

Maybe a mod or site developer can make a way to pull good comments out to a separate answer so that attributions and reputation scoring can be settled correctly

2
  • I added sleep 1; in the beginning, as otherwise the monitor would immediately turn back on. Aug 11 '20 at 18:53
  • The problem is maybe there isn't a function dpms -> ubuntu 21.04 hasn't
    – france1
    Jul 20 '21 at 18:52
2

You can set it with setterm remotely, just redirect your command to correct TTY on your laptop screen, usually is /dev/tty1.

Try this:

TERM=linux setterm --blank 1 <> /dev/tty1
0

I was having the same problem. What I discovered is that on my laptop (an old acer aspire) the default screentoggle button is supported. This could be something like fn+F6.

This solution probably didn't work back in the day. I hope it'll help anyone that encounters this problem.

1
  • 1
    Ubuntu 20.04 Me Too, but I need something from commandline. On my Acer xset dpms force off does not work. chvt 2 && setsid sh -c 'TERM=linux setterm --blank force <>/dev/tty2' (run as root via ssh) works, though, but often X11 crashes doing so, rendering screen+keyboard dead. In that case, networkmanager seems to be unable to keep network connections alive, so the machine is neither dead nor alive afterwards. All you can do is a long press of the power button. Checkmate.
    – Tino
    Feb 9 '21 at 19:28
0
  • Suggested way:
xset -display $DISPLAY dpms force off

Move your mouse and your screen will come back

  • Not suggested way:
xrandr --output $(xrandr | grep ' connected' | cut -d' ' -f1) --off

Then you lose your screen until you restart your machine or replug your monitor wire :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.