Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There has been a similar question - but IMHO there has to be a simpler solution. If num-lock is on in the BIOS - why is it turned off during linux boot and/or KDE/Gnome/whatever startup?

share|improve this question
up vote 8 down vote accepted

Linux initializes most peripherals so that they'll be in a known state. This includes the keyboard: Linux's internal data about the keyboard had better match the LEDs, so what Linux does is to turn off the LEDs (as far as I recall, the CPU can't read the state of the LEDs on a PC keyboard) and declare all *Lock to be off.

I like to have NumLock on by default. For Linux text consoles, what I used to do¹ is to run

for t in /dev/tty[0-9]*; do setleds -D +num <$t; done

from a boot script (/etc/rc.local or /etc/init.d/50_local_setleds or wherever the distribution likes to put those).

Nowadays, at least on some distributions such as Debian, you can add LEDS=+num to /etc/console-tools/config (or /etc/kbd/config depending on which one you have).

The X window system has its own keyboard handling, so you need to deal with it separately. What I do is to switch caps lock permanently off (I don't have a Caps Lock key in my layout) and switch num lock permanently on (I don't have a Num Lock key in my layout, and the keypad keys send KP_1 and so on). If you want to retain the modifiers but make Num Lock default on, you can write a small program to call XKbLockModifiers to set the modifier inside X and XChangeKeyboardControl to set the physical LED.

¹ Used to, because I haven't bothered with text consoles in a while.

share|improve this answer
You mention consoles - was there not a kernel-option for numlock in old linux-kernels? 0.x or 1.y? Anyway - is there no Xconfig-option for numlock? – Nils Oct 26 '11 at 21:08
@Nils Mmmm maybe, I don't remember. I don't think there's anything for X, but I learned about keyboards in X before XKB existed, so I might be missing some of that newfangled stuff from the very late 20th century. – Gilles Oct 26 '11 at 21:13
I'll add a note that on Debian, the setting numlock after boot is done by the kbd package which creates an kbd init script. – carandraug Apr 24 '14 at 22:11
^ and I can assert no longer works, presumably due to the takeover by systemd. – underscore_d Oct 6 '15 at 22:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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