Use the command to turn off the Linux server display
Overview
Generally speaking, turning off the monitor only requires pressing the monitor's power button. However, if the monitor does not have a power button or there are other reasons, you need to use a command to turn off the monitor.
Solution
First solution
On linux, you can turn off the monitor with the following command:
setterm --blank 1
However, this command can only be used locally. If you want to turn off the monitor remotely, you need to make the command into a service and then call the service remotely through ssh to turn off it.
1.Create /usr/local/bin/screen-off.sh.
#!/bin/bash
setterm --blank 1 --powerdown 2
2.Add executable permission to the script.
sudo chmod +x /usr/local/bin/screen-off.sh
3.Create /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=/usr/local/bin/screen-off.sh
[Install]
WantedBy=local.target
4.Automatically start at boot time.
sudo systemctl enable screen-off.service
5.Temporarily enable or disable.
sudo systemctl start screen-off.service
sudo systemctl disable screen-off.service
Second solution
This solution directly modifies grub and does not have the limitation of remotely shutting down the monitor via ssh, so it is more thorough.
1.Modify /etc/default/grub.
sudo vi /etc/default/grub
2.Add consoleblank=60 after GRUB_CMDLINE_LINUX_DEFAULT="quiet", where 60 means turning off the monitor after 60 seconds.
GRUB_CMDLINE_LINUX_DEFAULT="quiet consoleblank=60"
3.Update grub.
sudo update-grub
4.Reboot.