124

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
  • 13,874
darryn.ten
  • 1,473

13 Answers13

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
  • 117,780
  • So I followed the instructions over at the wiki page you linked to. I did the update command you list here. I did sudo apt-get install numlockx. But I didn't use the y option. Is that necessary? Didn't say anything about it over at the wiki page so I didn't do any of that. I rebooted and everything but Numlock is still disabled at boot and at login screen. Will try the update command. Other than that, am I missing something else here? The option "default numeric keypad keys" from keyboard preferences doesn't concern boot settings so I didn't enable that. Should I? – Samir Jul 21 '13 at 13:26
  • 1
    This did not work for me. Answer by +luvr did however. – Clarkey Aug 24 '13 at 19:16
  • 8
    This no longer works on Xubuntu LTS 12.04. – Serge Stroobandt May 09 '14 at 16:39
  • 3
    -y option is for force answer "Yes" if apt-get question about to install it. BECAREFUL WITH THIS: sometimes -I think here it is not the case, at least not in my case- there is some cases when apt-get says that something is needed to remove; in that cases apt-get will ask you confirm that action. But, sometimes remove packages automatically using apt would cause several problems on your machine. As an example sometimes ask you for remove some graphical packages that are use for GUI'S. Even sometimes it has asked me to remove gnome-desktop and some gpu drivers...that will really messed up SO – Diego Andrés Díaz Espinoza Mar 12 '15 at 18:55
  • On newer systems, you need to edit your ~/.bashrc file. Add line numlockx on. – Jim Fell Mar 08 '21 at 14:34
  • 1
    kubuntu 20.4 error sudo sed -i 's|^exit 0.*$|# Numlock enable\n[ -x /usr/bin/numlockx ] \&\& numlockx on\n\nexit 0|' /etc/init.d/rc.local sed: can't read /etc/init.d/rc.local: No such file or directory – SL5net Dec 31 '21 at 10:29
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
  • 7,440
luvr
  • 431
  • How can I just verify that numlockx is installed? Should it appear on a dash search? – Samir Jul 21 '13 at 13:32
  • Do I have to remove greeter-session=unity-greeter or the user-session=ubuntu` from the file (lightdm.conf)? Or just the greeter-setup-script line below them? – Samir Jul 21 '13 at 13:35
  • Yup! This worked like a charm! Unlike the complicated instructions and commands given in the accepted answer. Thanks! I also enabled the option "default numeric keypad keys" as shown below. – Samir Jul 21 '13 at 13:40
  • 6
    On Ubuntu 13.10 this method prevented the display of the login screen on my machine. After the initial display of the Ubuntu logo, the monitor was simply showing that there is no signal (I tried to reboot a couple of times but it always ended up the same). Not knowing what else to do, I booted the system from a live USB and removed the line from lightdm.conf. After that the system loaded up again just fine. – tmt Jan 03 '14 at 15:57
  • @cascaval I had the same problem. What fixed it for me was installing the lightdm greeter (sudo apt-get install lightdm-gtk-greeter) then modifying the config so it used unity as before (edit /etc/lightdm/lightdm.conf and change the line to greeter-session=unity-greeter). THEN you can add the greeter-setup-script line, as described by @luvr. – Kevin Cooper Mar 18 '14 at 15:52
  • This also worked for me on Xubuntu LTS 12.04. – Serge Stroobandt Apr 30 '14 at 21:02
  • 5
    While I know this trick worked for me in past versions, it no longer seems to works in 14.04. Adding this line to lightdm.conf breaks the login process, sending me to Low Graphics mode and preventing a login with Nvidia drivers. Removing this line fixed the problem. – cowbell40 Jan 12 '15 at 19:28
  • 1
    I don't have the file /etc/lightdm/lightdm.conf But I have this /etc/lightdm/lightdm.conf.d/70-linuxmint.conf and it works!!! :D – Shayan Feb 28 '18 at 15:20
  • I agree with prior comments that this edit may and has indeed created undesired problems with low graphics/Nvidia and I could not login until I reverted the change. – mgus Aug 19 '20 at 08:29
  • kubuntu 20.4 error :Command 'gksudo' not found – SL5net Dec 31 '21 at 10:32
  • Flexible solution! I don't use lightdm, but added this to my fluxbox startup script. However numlockx does require window manager of some sort...hence the "x". – nathan Jan 02 '22 at 23:04
24

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
  • 169,590
  • 1
    What's the difference between /usr/share/lightdm/ and /etc/lightdm? Wouldn't the settings in the former folder be overwritten with updates, while in the second they wont or did I misunderstand the meaning of the folders? – Peter Raeves Oct 21 '14 at 08:39
  • @PeterRaeves: You are absolutely correct. Radu, I would suggest that you edit your answer accordingly. Editing a package file which is not under /etc can't be anything but a temporary hack. – Gunnar Hjalmarsson Nov 08 '14 at 22:32
  • This one worked for me – abhishah901 Sep 18 '15 at 04:19
  • This is the closest answer that helped me. I use Xubuntu 14.04 and the file was /etc/lightdm/lightdm.conf.d/10-xubuntu.conf and I added the greeter-setup-script=/usr/bin/numlockx on to the end of that file and it worked great! +1 for pointing me in the right direction! – Terrance Feb 03 '16 at 01:00
  • 2
    in 16.04 beta2 this will lead to this problem http://askubuntu.com/questions/141606/how-to-fix-the-system-is-running-in-low-graphics-mode-error – Geng Jiawen Apr 06 '16 at 09:28
  • I don't have that file, I only have these: 50-disable-log-backup.conf 50-guest-wrapper.conf 90-nvidia.conf 50-greeter-wrapper.conf 50-xserver-command.conf 90-slick-greeter.conf – Shayan Feb 28 '18 at 15:15
  • It did work on Ubuntu 16.04! Nice... – Giannis Mar 19 '18 at 13:41
  • in Ubuntu 16.4, i found file "/usr/share/lightdm/lightdm.conf.d/60-lightdm-gtk-greeter.conf" and it worked after correctly edited the file. – soMuchToLearnAndShare Nov 01 '18 at 11:26
  • In Ubuntu 18.04 (for my system) the config file was -- 50-ubuntu.conf. – testuser Jan 30 '19 at 08:31
18

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,524
  • 1
    it's not this case, i make this procedure by the way. I press the button "Num Lock" and immediately it's goes off, "don't stay on". I had checked the keyboard and it's ok in other machine and other o.s. I change the keyboard to an older ps/2 keyboard to test. It seems that works, ie, there is some problem with USB keyboard in ubuntu 12.04 – Brunno May 04 '12 at 14:12
  • what is a Dash Search? my mine is ubuntu 16.4, and i have not seen Keyboard Layout options (searched under settings, only for keyboard, and it did not have the 'default numeric keypad keys'. – soMuchToLearnAndShare Nov 01 '18 at 11:14
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
  • 3,169
Abu Abdallah
  • 2,204
  • 6
  • 25
  • 38
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
  • 107,631
4

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

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,271
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
  • 865
  • Ubuntu Mate 20.04: With all the different similar config files I couldn't believe it would just be that file. So I tried the setting in 10's of files. Then I found a settings panel Login Window , where I could just turn this on. Which writes /etc/lightdm/slick-greeter.conf with exactly that value. After which it works as expected. – Spangaer Oct 31 '21 at 12:19
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,268
  • 1
  • 48
  • 59
0

19.04 DISCO DINGO

SETTINGS > KEYBOARD> BEHAVIOUR> GENERAL

Num Lock state reset

SDW_1980
  • 172
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
  • 628
  • 9
  • 22
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
  • 865