sudo apt update
sudo apt install openssh-server && sudo systemctl status ssh
When UFW is enable on ubuntu installation you will need add ssh to firewall rules
sudo ufw allow ssh
sudo apt install ubuntu-server && sudo reboot
sudo systemctl set-default multi-user.target && sudo reboot
sudo apt remove ubuntu-desktop -y && sudo apt autoremove -y && sudo apt autoclean -y && sudo reboot
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 1
And make script file executable by systemctl. Create file
/etc/systemd/system/screen-off.service
with contents:
[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]
# attention this can change to your system, during first steps enabling server, this has been changed to multi-user.target
# WantedBy=local.target
WantedBy=multi-user.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
SOLUTION (verified with Ubuntu 20.04 server running on a laptop)
Create a file:
sudo nano /etc/systemd/system/enable-console-blanking.service
And put this into the file:
[Unit]
Description=Enable virtual console blanking
[Service]
Type=oneshot
Environment=TERM=linux
StandardOutput=tty
TTYPath=/dev/console
ExecStart=/usr/bin/setterm --blank 1
[Install]
# attention this can change to your system, during first steps enabling server, this has been changed to multi-user.target
# WantedBy=local.target
WantedBy=multi-user.target
Then change the file rights and enable the service:
sudo chmod 664 /etc/systemd/system/enable-console-blanking.service
sudo systemctl enable enable-console-blanking.service
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=1 to GRUB_CMDLINE_DEFAULT, it should look like this:
GRUB_CMDLINE_LINUX_DEFAULT="quiet consoleblank=1"
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)
curl -fsSL https://get.casaos.io | sudo bash