Apple magic keyboard mapping problem under Linux

If you have a brand new Apple Magic Keyboard and you’re getting wrong key mappings for < as " and > as é, you can fix this problem with the following command:

$ setxkbmap -option apple:badmap

If it is works for your environment too, edit /etc/default/keyboard file and add or replace XKBOPTIONS value as below to make changes permanent:

XKBOPTIONS="apple:badmap"

EDIT: If the keyboard connected with Apple Lightning usb cable on Linux bootup, it is not used as a bluetooth keyboard anymore. This time it is recognised as an “AT Raw Set 2 keyboard”. But on this case, if you also provided apple:badmap option described in first part of the tutorial, you’ll get the same problem again!

When this is the case, run following command to reset xkboptions:

$ gsettings reset org.gnome.desktop.input-sources xkb-options

and if everything starts to work correctly, you should think about whether do change XKBOPTIONS variable in /etc/default/keyboard file to its original state or not, depending on your keyboard usage, using through bluetooth or cable.

(Tested on Debian 10)