126

I am trying to force numlock to be on upon initial boot at the login screen on Ubuntu 12.04. The only solutions I have found so far switch numlock on only after initial login.

I'm looking to force numlock to be on when the login screen is displayed, and before the user has logged in. Can anyone assist?

Jjed
  • 14,064
darryn.ten
  • 1,493

14 Answers14

79

On many machines, you can set whether or not Number Lock is turned on on boot, in the BIOS settings (accessible when you first power on the machine).

Otherwise, there are a number of ways to enable (or disable) Number Lock in software, depending on your specific needs. The most useful ways are listed here.

If you want Number Lock turned on when Ubuntu starts (not before that on the GRUB menu, and not afterwards when logging in, and not just for specific virtual consoles), then install numlockx and make the initialization script /etc/init.d/rc.local use it to enable Number Lock:

sudo apt-get update
sudo apt-get -y install numlockx
sudo sed -i 's|^exit 0.*$|# Numlock enable\n[ -x /usr/bin/numlockx ] \&\& numlockx on\n\nexit 0|' /etc/init.d/rc.local

Source: NumLock, by Contributors to the Ubuntu documentation wiki, last line taken verbatim (as this source permits).

Eliah Kagan
  • 119,640
43

Here's what worked for me:

  1. Ensure that numlockx is installed:

     sudo apt-get install numlockx
    
  2. Edit the file /etc/lightdm/lightdm.conf:

     sudo nano /etc/lightdm/lightdm.conf
    
  3. Add the following line to the file:

     greeter-setup-script=/usr/bin/numlockx on
    

    Press Ctrl + X to exit Nano.

Error404
  • 8,278
  • 3
  • 35
  • 60
luvr
  • 431
25

14.04

Yes, use locate command as follow:

locate 50-unity-greeter.conf

The output is:

/usr/share/lightdm/lightdm.conf.d/50-unity-greeter.conf

So, the file you need to edit is the above file.

sudo apt-get install numlockx
gksu gedit /usr/share/lightdm/lightdm.conf.d/50-unity-greeter.conf

Add this line at the end of file:

greeter-setup-script=/usr/bin/numlockx on
Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
19

For Enabling it on Login Screen

First, ensure that numlockx is installed, by typing these in terminal:

sudo apt-get install numlockx

Then, edit the file /etc/lightdm/lightdm.conf

gksudo gedit /etc/lightdm/lightdm.conf

Add the following line to the file:

greeter-setup-script=/usr/bin/numlockx on

For Enabling Numlock by Default after Logging In..

  1. In Dash Search for Keyboard Layout and open it
  2. In the window that opens on the ottom right there is Options, click on it.
  3. Under Miscellaneous compatibility options, Enable Default Numeric Keys.

enter image description here

sarvesh.lad
  • 2,534
7

Ubuntu 18.04

Open terminal by Ctrl+Alt+T

Run commands

sudo -i
xhost +SI:localuser:gdm
su gdm -s /bin/bash
gsettings set org.gnome.settings-daemon.peripherals.keyboard numlock-state 'on'
gsettings set org.gnome.desktop.peripherals.touchpad tap-to-click true

That's it...

Solution by

In Ubuntu 20.04

To Keep it on

gsettings set org.gnome.desktop.peripherals.keyboard remember-numlock-state true

To Keep it off

gsettings set org.gnome.desktop.peripherals.keyboard numlock-state false

You can configure the way you like.

sotirov
  • 4,379
Abu Abdallah
  • 2,244
6

I have done this, and it worked for me. First, make sure you have universe repository added.

Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the commands below.

sudo apt-get update
sudo apt-get install numlockx

Now that numlockx is installed, create a file named Default in /etc/X11/ with these contents:

if [ -x /usr/bin/X11/numlockx ]; then
    /usr/bin/X11/numlockx on
fi

exit 0

Turn off your Num Lock and reboot. Voilà!

Mitch
  • 109,787
3

Most BIOSes allow this to be enabled. You can check your BIOS for this feature.

OR

Go to : System Settings -> Keyboard Layout -> Options -> Miscellaneous compatibility options

Check "Default numeric keypad keys"

Sources : https://help.ubuntu.com/community/NumLock

Vibhav
  • 4,343
3

Xubuntu specific.

Versions from 14.10 include a pkexec mousepad action.

Follow previous answers to install numlockx

Edit /usr/share/lightdm/lightdm.conf.d/60-lightdm-gtk-greeter.conf as root

Alt+F2 then

pkexec mousepad /usr/share/lightdm/lightdm.conf.d/60-lightdm-gtk-greeter.conf

Add

greeter-setup-script=/usr/bin/numlockx on

then save.

2

If you are using lightdm you can add a file /etc/lightdm/slick-greeter.conf with

[Greeter]
activate-numlock=true

That will enable numlock at the login screen. I have encountered a small bug in the panel LED applet that shows indicators for numlock, scroll lock and caps lock. If you use this method then the indicator will show off, despite numlock being on. If you toggle numlock it will show the correct status.

To fix this add a startup application with the startup application app and add this command.

bash -c 'numlockx off && numlockx on'

Of course you need to install numlockx. If you do not use the indicator applet then you can probably ignore this last part.

FalcoGer
  • 925
2

Here is a little bash script which takes care of everything in an automated way:

#!/usr/bin/env bash
FILE='/etc/lightdm/lightdm.conf'
KEYVALUE='greeter-setup-script=/usr/bin/numlockx on'
sudo apt --yes install numlockx
grep --quiet "$KEYVALUE" "$FILE" || echo "$KEYVALUE" | sudo tee --append "$FILE"

Do not forget to first make your bash script executable with chmod +x scriptname, then execute it with ./scriptname.

Serge Stroobandt
  • 5,719
  • 1
  • 54
  • 59
0

19.04 DISCO DINGO

SETTINGS > KEYBOARD> BEHAVIOUR> GENERAL

Num Lock state reset

SDW_1980
  • 172
  • 3
  • 13
0

From the K Menu, launch System Settings and click on Keyboard (Edgy users: K Menu -> System Settings -> Keyboard and Mouse -> Keyboard). You can see in the middle section the options for "NumLock on KDE Startup", where you can choose to Turn On, Turn Off, or Leave Unchanged.09.07.2021

a copy from https://help.ubuntu.com/community/NumLock

SL5net
  • 698
  • 10
  • 28
0

For Ubuntu Mate 22.04 (Jammy Jelly) with lightdm and arctica-greeter you can edit the configuration with dconf-editor in /org/ArcticaProject/arctica-greeter/. This is the official way and requires to run dconf-editor as the lightdm user, which is a problem. Settings done here take no effect if done as root or user. enter image description here

A workaround for this bug is to create a gschema.override in /usr/share/glib-2.0/schemas/ with for example sudo vim /usr/share/glib-2.0/schemas/99_arctica_greeter.gschema.override and then recompile the schemas with sudo glib-compile-schemas /usr/share/glib-2.0/schemas/

The schema could look something like this:

[org.ArcticaProject.arctica-greeter]
background='/home/user/Pictures/fuchs/snowfox.jpg'
activate-numlock=true
play-ready-sound=false

Add any other keys that you see in dconf-editor and adjust as required and then recompile the schemas.

FalcoGer
  • 925
0

I tested this solution in Xubuntu 24.04 but it also appeared here in 2015 in a now deleted answer, so it seems to be quite stable.

Install the numlockx package:

sudo apt-get install numlockx

Open its configuration file with your favorite editor:

sudo editor /etc/default/numlockx

Make sure the line starting with NUMLOCK reads:

NUMLOCK=on

Save the file.

Melebius
  • 11,750