These instructions are written from a Debian based system, but may work similarly on other Posix/Unix/Linux/BSD desktops.
WARNING: make backups of any system files before altering them
The Arch wiki details some methods that are not included here. Including enabling numlock in the virtual TTYs.
If numlock is not enabled by default with the startup of your system but you would like it to be so, the following instructions may be helpful.
Contents
TTY
Numlock can be enabled in the virtual TTYs after system startup by creating a system service.
Systemd
Many current Linux distributions use Systemd for managing system services. First thing to do is create a shell script that will enable numlock for all TTYs using the setleds command when executed.
Example: /usr/sbin/numlockttyon.sh
#!/bin/bash
for tty in /dev/tty{1..6}; do
/usr/bin/setleds -D +num < "$tty"
done
We can create another script for when the service is stopped.
Example: /usr/sbin/numlockttyoff.sh
#!/bin/bash
for tty in /dev/tty{1..6}; do
/usr/bin/setleds -D -num < "$tty"
done
Now we create a Systemd service file.
Example: /etc/systemd/system/numlocktty.service
[Unit]
Description=Numlock on TTYs
[Service]
ExecStart=/usr/sbin/numlockttyon.sh
ExecStop=/usr/sbin/numlockttyoff.sh
RemainAfterExit=yes
StandardInput=tty
[Install]
WantedBy=multi-user.target
The service file should be executable as well (as far as I can tell). Now reload the services daemon & enable the numlocktty service.
# systemctl daemon-reload
# systemctl enable numlocktty.service
Created symlink /etc/systemd/system/multi-user.target.wants/numlocktty.service → /etc/systemd/system/numlocktty.service.
# systemctl is-enabled numlocktty.service
enabled
At the next system restart, numlock will be enabled when you enter the virtual TTYs.
init
For a SysVinit service we will use the same shell script from the Systemd example & add an additional for checking if the service is active.
Example: /usr/sbin/numlockactive.sh
#!/bin/bash
for tty in /dev/tty{1..6}; do
setleds < ${tty} | grep "^Current flags:.*NumLock on" > /dev/null 2>&1
res=$?
if [[ ${res} -ne 0 ]]; then
exit ${res}
fi
done
exit 0
Now we create a service shell script in /etc/init.d.
Example: /etc/init.d/numlocktty
#!/bin/bash
### BEGIN INIT INFO
# Provides: numlocktty
# Default-Start: 2 3 4 5
# Default-Stop: 0 6
# Short-Description: Enables numlock for TTYs.
### END INIT INFO
set -e
case "$1" in
start)
/usr/sbin/numlockttyon.sh
;;
stop)
/usr/sbin/numlockttyoff.sh
;;
status)
/usr/sbin/numlockttyactive.sh
exit $?
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|status}" >&2
exit 2
;;
esac
exit 0
Now enable the service:
# /usr/sbin/update-rc.d numlocktty enable
Login/Display Manager
You may want numlock to be enabled for use at the login screen. Unfortunately, there is no universal method (as far as I am aware) to do so. But it depends on the configuration of your login/display manager. I will go over the ones I am familiar with.
Note: The system may need to restart before changes to display manager settings take effect.
lxdm
Configuring lxdm is simple. Edit the file /etc/lxdm/lxdm.conf or /etc/lxdm/default.conf & uncomment the line “# numlock=0” & set it’s value to “1”.
sddm
sddm also has a fairly simple configuration located at /etc/sddm.conf. If the file doesn’t exist, a default configuration can be generated using the following command.
# sddm --example-config > /etc/sddm.conf
But you really only need two lines:
[General]
Numlock=on
gdm3
From a terminal execute the following commands.
$ sudo -i
# xhost +SI:localuser:gdm
# su gdm -s /bin/bash
# gsettings set org.gnome.desktop.peripherals.keyboard numlock-state true
xdm & wdm
TODO
The following require numlockx. See instructions below.
lightdm
Find where lightdm stores its configuration files. On my system they were located in the directories /usr/share/lightdm/lightdm.conf.d & /etc/lightdm/lightdm.conf.d. Create a new file under one of these directories with the .conf extensions. I used 50-numlock.conf. Add the following as its sole contents.
[Seat:*]
greeter-setup-script=numlockx on
numlockx
numlockx is a command line utility that simplifies managing the numlock state. Most Linux/BSD systems make this available from their official package repositories.
Debian based systems:
# apt install numlockx
Arch based systems:
# pacman -S numlockx
Red Hat/Fedora based systems:
# dnf install numlockx
FreeBSD based systems:
# pkg install numlockx
or
# cd /usr/ports/x11/numlockx && make install
OpenBSD based systems:
# pkg_add numlockx
or
# cd /usr/ports/x11/numlockx && make install
On some systems, simply installing numlockx may be all you need to do. If it detects that the system is running on a laptop it will leave numlock disabled by default, even if you have a number pad.
From a command line terminal, there are three simple commands for numlockx:
$ numlockx on # set numlock state to on
$ numlockx off # set numlock state to off
$ numlockx toggle # toggle current state between on/off
$ numlockx status # display current state
Note: numlockx requires an X session. So executing from a tty terminal without X running will fail.
Your system may or may not use the same status as the display manager after login. If not, you can try the following suggestions.
Global User Session
There are multiple configuration files or startup scripts where numlockx can be invoked. The simplest solution is edit numlockx’s configuration file located at /etc/default/numlockx. Change the line “NUMLOCK=auto” to “NUMLOCK=on” or “NUMLOCK=keep”. If set to “keep”, it will use whichever state was last used at login. This configures the numlock state system-wide for any user that logs in.
profile.d & bash.bashrc
Another possible solution is to invoke numlockx in the shell startup scripts. Create a new file in /etc/profile.d with an .sh extension & put “numlockx on” as its sole contents. Or, if your system is running bash, you can add it to the end of the /etc/bash.bashrc script. If this does not work, it is possible the state is being overridden by the setting in /etc/default/numlockx.
Single User Session
If you only want to configure numlock for a single user session, & your session manager does not offer a setting for it, you can try one of the following. How numlockx is invoked depends on which scripts are executed at login.
.profile & .bashrc:
Add “numlockx on” to the end of either the .profile or .bashrc or .bash_login script in your home directory.
.xinitrc & .xsessionrc:
According to documentation, if the desktop environment was launched with the xinit or startx command, it should read the scripts .xinitrc or .xsessionrc in the user’s home directory. In theory, adding “numlockx on” to one of these should work. But it did not for me.
Some other instructions were to copy the xinit initialization script to the user home directory as .xinit or .xinitrc. On my system the script was located at /etc/X11/xinit/xinitrc. This file needs to be executable & will contain something like this:
#!/bin/sh
# /etc/X11/xinit/xinitrc
#
# global xinitrc file, used by all X sessions started by xinit (startx)
# invoke global X session script
. /etc/X11/Xsession
In theory, again, adding “numlockx on” to this file should work. But did not for me. I tried adding the line before & after /etc/X11/Xsession is executed.
Desktop launcher:
If your desktop session supports it, you can create a launcher in the ~/.config/autostart directory with the extensions .desktop. Example: ~/.config/autostart/numlock.desktop. Add the following to it:
[Desktop Entry]
Exec=numlockx on
Name=Numlock On
Type=Application
Version=1.0
crontab:
Another suggestion that did not work for me was to add the command to the user’s crontab. Execute crontab -e to edit the user’s crontab. Then add the line “@numlockx on”.

















