Ubuntu: How can I blank the screen from the command line over SSH?


I need a way to show black screen by running command in console by using SSH connection. Monitor should not go to standby I just need a black screen to hide everything that is on the screen. Screen should be black until I give another command to show screen content.

Addition: It would be good if the command worked in Ubuntu, Lubuntu and Xubuntu.

Addition 2: I have also a projector that needs blanking. I want to use SSH to connect to my server and show blank screen. If I try to power off the projector "No signal" is shown on the screen.


Short answer:

xrandr --output DVI-I-1 --brightness 0  

where DVI-I-1 is your screen's name.

The other way around:

xrandr --output DVI-I-1 --brightness 1  

to set to normal brightness again.

To get the screen's name

Simply run the command:


In the output, you will find the screen's name, in the line, including connected

Small script to either darken the screen or set it back to normal

The script can be used to set (all) connected screen(s) to black and vice versa. The script finds your screens automatically.

#!/usr/bin/env python3  import subprocess  import sys    arg = sys.argv[1]    screens = [l.split()[0] for l in subprocess.check_output("xrandr").decode("utf-8").splitlines()             if " connected" in l]    val = "0" if arg == "black" else "1"  for s in screens:      subprocess.Popen(["xrandr", "--output", s, "--brightness", val])  

To run

  • Copy the script into an empty file, save it as set_black.py
  • Run it either with:

    python3 /path/to/set_black.py black  

    to darken the screen, or

    python3 /path/to/set_black.py normal  

    to set brightness to normal again.

While the answer above should run fine on all Ubuntu distro's locally, the question turns out to be on ssh/remote (the information was edited into the question).

In case of a remote situation, we'd need to set the $DISPLAY variable correctly. If the display variable is e.g. :0, we'd need to run the script with:

DISPLAY=:0 python3 /path/to/script.py black  

The variable is not necessarily :0 though. This post on U&L seems an excellent one set the DISPLAY variable on the remote machine.


Simply run:

gnome-screensaver-command -a  

Note: This will also call the lockscreen unless you disable the "Lock" option in system settings:

enter image description here


Edit: The question has been changed since I had provided this answer. I will let this answer stand because it provides some information which may be of use.

If by console you mean one of the character-cell virtual consoles, then install vlock:

sudo apt-get -y install vlock  

You can then black out and lock your virtual console:


When unlocking the console the screen is not restored. If you don't want to lose the contents of the screen, the I suggest to login to a second console; when you want to lock the screen move to that second console and enter

vlock -a  

This will lock all consoles and prevent console switching. After unlocking the consoles you can switch back to the main work console and find your screen contents intact.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »