Linux disable screen blanking i.e. preventing screen going blank

last updated in Categories Linux, Troubleshooting

It is easy to disable screen saver under X window. But when it comes to text based login or terminal you will not find easy way to disable text based power saving mode (i.e. when your screen goes blank after a few minutes).

So how do I disable the blank screen mode, which activated after a few minutes? Answer is use setterm command.

setterm writes to standard output a character string that will invoke the specified terminal capabilities. Where possible terminfo database (terminfo is a data base describing terminals, used by screen-oriented programs and libraries such as ncurses) is consulted to find the string to use.

By default, the Linux kernel will use screen-save option to disable it you need to type command (it turns off monitor VESA powersaving features):

$ setterm -powersave off -blank 0

If it dumps back you with an error that read as follows:

cannot (un)set powersave mode

You need to shutdown X window system and rerun the above command. Better, add following two commands to your ~/.xinitrc file:

setterm -blank 0 -powersave off -powerdown 0
xset s off

Other useful options

This command also supports other useful options:
Resets the terminal to its power on state:

$ setterm -reset

Alternatively, initialize terminal:

$ setterm -initialize

Turns the terminal’s cursor on or off:

$ setterm -cursor [on|off]

Turns automatic line-wrapping on or off (virtual consoles only)

$ setterm -linewrap [on|off]

Sets the foreground text color (virtual consoles only):

$ setterm -foreground blue

Sets the background text color (virtual consoles only):

$ setterm -background red

Enables or disables the sending of kernel printk() messages to the console (virtual consoles only). Useful if you get lots message from iptables firewall:

$ setterm -msg [on|off]

I regularly use these (above) options.

See also:

  • Please consult the setterm and terminfo man pages for more information.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

22 comment

  1. I wouldn’t use “setterm -msg off”, as you don’t get useful panic messages. Rather use “dmesg -n1”, so that you still get panic messages but not all the trivial junk to the console. Otherwise thank you for a useful page

  2. Your guide was a great help, however it wasn’t enough for a clean approach on my Ubuntu 7.10 system.

    I don’t have an .xinitrc, so instead I put this in ~/.bashrc:
    xset s off > /dev/null 2>&1
    and this in /etc/rc.local
    sh -c 'setterm -blank 0 -powersave off -powerdown 0 /dev/console 2>&1'
    This also does not produce errors even though I’m running an X session.

  3. Somehow copy-paste screwed up before.
    Here’s the code for rc.local:
    sh -c 'setterm -blank 0 -powersave off -powerdown 0 /dev/console 2>&1'

  4. I’m very sorry to “spam” like this >_<
    Figured < was interpreted as an HTML-tag.
    Hopefully it should work now:
    sh -c 'setterm -blank 0 -powersave off -powerdown 0 < /dev/console > /dev/console 2>&1'

  5. Great tips. Screen blanking used to irritate me on the console, too. Especially for my servers which I KVM into. There’s no screen to burn out, so why should the term go blank?

    Anyway, I wanted to add that sometimes I’ll do something dumb, like cat’ing a binary file, and it completely screws the terminal window. The way to recover from that is just the ‘reset’ command. A lot of people probably don’t know that.

    Before I learned about it, sometimes I’d be up to 3 or 4 terminals lost to garbage on the screen. Logging out never helped, and I used to have to restart the machine to recover them. ‘reset’ fixed that.

  6. also you can just execute
    echo -e ’33[9;0]33[14;0]’
    if your terminal supports CSI-sequences (if you use linux – you may shure that it does)

  7. To disable the screen blanking I put the suggested line into /etc/inputrc on my ubuntu server (no .xinitrc)

    thanks, I like your pages (and format), they always seem to hit the problem right on the head.


    1. Thank you so much! This comment saved me much trouble.
      I’m somewhat of an ubuntu newbie, and chose to run a distro without a GUI to save resources for my minecraft server =P

    2. That is a horrible idea! I tried this on a Debian system (which is what Ubuntu is usually built upon) and it disabled my ‘x’ and ‘s’ keys in bash. I would not advise anyone to do this.

  8. How do I make this permanent? I did the lines Helge put up but once I reboot the system, it goes back to blank out the screen after about 15 mins.

    I’ve previous turned off acpid and apmd with chkconfig.

    I need to have the device load everything and remain with an active screen indefinitely. So far the only thing that lets me do that is this setterm command, however, when I reboot – it goes away.

  9. i am try to use your command in redhad but it is not work
    i already have screensaver in terminal 7 and i try to disable it from another terminal with $ setterm -powersave off -blank 0
    i do not get any error but it is not work and screensaver still work
    also when i am try to use comman in gui by xset s off it also did not work i not know
    i hope anyone could help me please

  10. In case anyone is still interested, there seems to be a “feature” in ktorrent that re-enables dpms. Problem aparently appeared after an update.
    “xset -dpms” is run on startup, so screen doesn’t go blank. “xset -q” confirms this. Then running ktorrent and checking again with “xset -q” and dpms is again enabled, moreover – sometimes it will shut down in 48 seconds, other times in 110, other times in 600.
    I traced the problem to be in ktorrent’s “prevent suspend when torrents are running” option. If you disable this option then starting ktorrent doesn’t mess around with the dpms settings.

    I hope this helps someone out there.

  11. Thanks a lot for this solution 😀 NO MORE BLANKING YAY!!!

    It’s such a pain in the S!!!
    Whoever came up with this BS should be forced to stare at their stupid screen blanking 24/7, hands tied to their chair and all input devices diconnected.
    …10 minutes… what a stupid delay anyways. it’s just right to be annoying, bullying and griefing people. Whatever you do…coffee, smoking, toilet you always arrive just in time to see your screen go blank. Oh and every 10 minutes while reading something… awesome, really well thought out. i’m sure that a PhD or two are required to come up with such turn-off-my-screen-for-the-sole-purpose-of-being-a-major-pain-in-the-s crap.

  12. Sorry if I missed this somewhere, but is this command long lasting? Or does it have to be redone after a reboot of the server?

  13. I was having requirement to disable the screen saver in Knoppix Linux. So I have added the below commands in “” (without need to remaster). It worked fine.

    setterm -blank 0 -powersave off -powerdown 0
    xset s off

    Thank you.

  14. although old, you can’t afaik use the kernel-param ‘consoleblank=0’ with the setterm utility but need to add as a kernel parameter.
    on debian-based systems booting through grub2 this can be achieved by editing /etc/default/grub and adding the param to the line starting with ‘GRUB_CMDLINE_LINUX_DEFAULT=’. if this line is not present yet simply add it with ‘consoleblank=0’ as the only param, if its present simply append it after a blank-character. don’t forget to update grub (typically through ‘sudo update-grub’) after saving your changes.

    @andrew: your hint helped me to successfully solve my screen-blanking issues on a system that doesn’t provide a setterm utility, thanks!

    Have a question? Post it on our forum!