Impossible to change keyboard layout on lightdm at login

I installed Ubuntu Mate 19.10 on my cousin laptop, during install process I selected only french keyboard and used a simple user password composed of numbers, but after login I added arabic keyboard layout because it's her native language, and then my cousin changed her password to something in arabic, everything worked fine but only after rebooting we found that lightdm give us only french keyboard and even if I click on keyboard indicator or use shortcut Alt+Shift, nothing works and she is now stuck and can't access her session, how can I add another layout to lightdm and be able to choose it at login?

First, I would try to log in using tty terminal.

  1. When in the lock screen, press ctrl + alt + F2.
  2. Try to log in by entering username and password.
  3. If it works, then run this command: L='ar' && sudo sed -i 's/XKBLAYOUT=\"\w*"/XKBLAYOUT=\"'$L'\"/g' /etc/default/keyboard. This will let you change keyboard configuration.
  4. Press ctrl + d to logout.
  5. Then press ctrl + alt + F7 to go back (and maybe reboot).

However, if you can't log in, then boot into a live USB and follow these instructions:

  1. Open GParted and go to the harddrive/ssd to locate the installed partitioned. (If GParted is not installed, install it by running sudo apt install gparted) The installed partitioned should be ext4.
  2. Now open a terminal, and run sudo mount /dev/{THEPARTITION} /mnt (replace {THEPARTITION} with what ever the install partition appears as in gparted. It could be something like sda2, sdb6, nvme0n1p4, or whatever else. Make sure to switch devices to the harddrive/ssd not the USB--option is top right of gparted)
  3. If you have seperate /usr partitions or /var partitions then also mount them same way. (if you don't know whether you have separate partitions or not, then you probably don't) For example, mounting the /usr partition: sudo mount /dev/{THEUSRPARTITION} /mnt/usr
  4. Bind mount other stuff: for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done
  5. Run sudo chroot /mnt. This will log you in as root into your installed partition.
  6. Now follow steps 3 and 4 from the first method, and then reboot.

If nothing works, then I don't know :confused:

Next time you gain access to login (whether on a new installation or on this installation), I would suggest setting up the password for the root user just in case something else happens. That way you can always log in to it using tty terminal. But I guess if the keyboard is in another language, then you can't...

1 Like

The first method didn't work, but the second method (live USB) when I tried to install console-common it wanted to remove also lightdm, should I continue and remove it ?


Will this remove lightdm from live session or from my installed mounted partition ?

No, don't do that. You are logged in to the installed, mounted partition...

Actually, I just read that the dpkg-reconfigure is only temporary, so it wouldn't work.
Mount everything again and chmod in it, then follow this guide, specifically, the "Permanently Configure keyboard in Ubuntu" section.

Edit: I think ar is Arabic, so run L='ar' && sudo sed -i 's/XKBLAYOUT=\"\w*"/XKBLAYOUT=\"'$L'\"/g' /etc/default/keyboard I guess.

Edit 2: Also, for your general information, in case something else happens, and you need to edit say grub, then you might also need to mount the EFI partition before chmod, but in this case, you did not need to mount /boot/efi because we are not editing it or using it.

Edit 3: Ok, last edit for real. Usually, its better to copy and paste from terminal rather than giving a screenshot. It's easier to read and saves storage on server.

OMG, it really worked by replacing "fr" by "ar" inside /etc/default/keyboard, thanks really for your great help, now she is happy and she also thanks you a lot :kissing_heart:

What I understand from this problem is that lightdm uses separate keyboard layouts from what MATE uses, and that keyboard indicator in the login greeter is only there for displaying current layout and can't change default layout to new one or to one from layouts used inside MATE.

I believe the language you set up initially is used as the default, system-wide language. Then, any keyboard settings you change within is only applied to the user (configs are saved in the home directory).
Don't quote me.

This is really serious bug or bad design by default, because on Windows the keyboard layout can be changed in any stage of usage of the OS.

1 Like

Maybe post here: What's your most important bugfix or new feature for 20.04?

1 Like