Skip to content

Yubikey and French keyboard layout on Ubuntu

November 24, 2012

If you use a Yubikey with a French keyboard layout and set the Yubikey to OATH-HOTP mode (i.e the key generates 6–8 digits number) then you’ll probably have experienced this disappointing behavior: the key sends non-numerical values that correspond to their numerical values on a french keyboard layout.

This is because the key sends keycodes corresponding to the digits row on the keyboard but digits, on a French layout, are shifted.

The workaround is trivial, hold the <SHIFT> key before touching the YubiKey to get the digits.

If you own a key with firmware 2.3 , you can use the option ‘-o use-numeric-keypad’ and the key will generate a numerical sequence, even with a French keyboard.

But there is no such option with firmware 2.2 and earlier. If you don’t want to burn passwords because you forgot to press the <SHIFT> key then you can configure your system to recognize the key and set it up to use a US keyboard.

The old school way is to configure the device manually in /etc/X11/xorg.conf and add an entry like:

Section "InputClass"
    Identifier "yubikey"
    MatchVendor "Yubico"
    MatchProduct "Yubico Yubikey II"
    Option "XkbModel" "pc101"
    Option "XkbLayout" "us"
    Option "XkbVariant" "intl"
EndSection

But desktop environments like Unity/Gnome or KDE override these settings and there is no UI way (at least for gnome) to configure several keyboards with different layouts. A solution is to use setxkbmap and a udev rule to reconfigure the keymap of the yubikey.

The script below set a US keymap, you can paste it to /usr/local/bin/setyubikeymap

#!/bin/sh

. /lib/udev/hotplug.functions

logger "YubiKey inserted - Setting keymap to US"
eval $(xargs -n 1 -0 < /proc/$(pgrep -f ^gnome-session)/environ| awk '/^DISPLAY|^XAUTHORITY/ {print "export", $0}')

exec 1<&- 2<&- 5<&- 7<&-
(
    wait_for_file /dev/input/by-id/usb-Yubico_Yubico_Yubikey_II-event-kbd
    exec /usr/bin/setxkbmap -device $(/usr/bin/xinput list --id-only 'Yubico Yubico Yubikey II') us
) &

Then add the following rule to /etc/udev/rules.d/99-yubikey to call the script when the key is inserted

# Udev rules for setting keymap of the Yubikey USB to US
ACTION=="add|change", SUBSYSTEM=="usb", \
ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0010", \
RUN+="/usr/local/bin/setyubikeymap"

The script can surely be improved and be more robust but you get the idea. Also the key sometimes loses its configuration on resume from suspend, which is probably fixable with a pm hook.

Hope this helps French keyboard users!

About these ads

From → Ubuntu

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: