Tuesday, 21 August 2012

Fixing UK keyboard mapping for Xrdp

Xrdp is a pretty nice tool for accessing a Linux box from Windows - you can use the Windows built in remote desktop client rather than having to install some flavour of VNC. It all just works - nearly...

The trouble is that Xrdp doesn't seem to support X windows keyboard mappings properly. I pretty quickly noticed that my ",@,#,~,\,|,£ characters were behaving as though I had a US keyboard not a UK one.

First point of call was the X keyboard settings UI, which oddly was blank with no additional layouts to choose from or options to set. Going to the same settings under an X login on the machine itself was fine. Hmmm...

A little digging revealed this post which outlines the approach to take to generate a new keyboard map for xrdp. For en-gb you need to create a 'km-0809.ini' file and install it into /etc/xrdp. Unfortunately, while this keyboard map fixed the #,@,| etc characters, it broke the arrow keys, page up, page down, home, end and possibly a whole load of other utility keys too.

Fortunately text based configuration files and a diff viewer (Meld) came to the rescue. I was able to cherry pick the changes that I did want from the 0809 ini file and apply them to a copy of the default US english (0409) ini file. I found the list of key codes that I wanted to move across by using the 'xev' tool to record keypress information on the problem keys.

Once the file was finished, it only needs to be copied to /etc/xrdp/km-0809.ini and given the right ownership and permissions. Then restart the xrdp service and you should be done

Here are the commands (on Ubuntu 12.04) to setup the permissions etc and restart the service

sudo chown xrdp.xrdp /etc/xrdp/km-0809.ini
sudo chmod 644 /etc/xrdp/km-0809.ini
sudo service xrdp restart

Here is the corrected UK English keyboard file : km-0809.ini


  1. Thanks Robin - I had this issue trying to run my Raspberry Pi "headless" and connecting to it via RDP. I spent much time but only managed to get to the point where I had a new, but broken, km-0809.ini file. Thanks for your perseverance in getting to a full solution.


  2. Robin,

    Much appreciated! Saved me a lot of time and headache this. For reference this works on Fedora 17 as you have shown. The only difference is that all files in /etc/xrdp/ are owner:group root.


  3. Really appreciate this, someone else was good enough to post it on my SuperUser question about this http://superuser.com/questions/436838/how-do-i-change-the-xrdp-keyboard-layout-to-en-gb-in-ubuntu-12-04 so very grateful to finally have a fix!

  4. Many thanks! I was part way through doing exactly what you did when I saw this post. We really need to try to get this into the standard xrdp sources so it flows through to all distributions.

    Does anyone have any idea how to do that?

  5. Great - saved me a lot of hassle.

    Why xrdp does not include common keyboard layouts by default is a mystery to me.
    I have just logged it as a bug with Ubuntu.

  6. Thanks very much ... very helpful for me too

  7. Worked like a charm! Thanks a lot for doing the work so we don't have to.

  8. How do we set a different keyboard layout to each user that logins in xrdp?

  9. Legend - thank you! Looks like it's working like charm!

  10. Thank you, you've just saved me loads effort getting my headless pi working.

  11. Can I ask for a few hints on which file should I fight with? I'm trying to get xrdp to work with 'Polish Programmers'' layout, where right Alt key is crucial.
    Works ok on the console, via xrdp gets somehow screwed (keycode 92 is ok for right Alt, via xrdp it seems to be 113)

  12. Ok, ALMOST nailed it...
    I did
    xrdp-genkeymap for ALL the layouts I have on this test rig in /etc/xrdp (with current settings for pl layout), which gave me diacritics and intended Alt behaviour, the only messed up things seem to be Delete doing PrintScreen and Backspace doing Delete...

  13. Sir, you are a wizard. Much obliged.

  14. Brilliant - thanks for this - worked a treat

  15. Unfortunately this caused my remote keyboard to be none responsive on the RPi. I rebooted the RPi using the local keyboard, but still no joy with the remote keyboard.
    Using the local keyboard I removed the km-0809.ini file restarted teh xrdp service but the connection failed, so rebooted the RPi. Keyboard all working on the remote - but in US layout format.

    So back to square one. Worth a try though.

  16. I take that all back.

    More looking round the web I found everybody points to your site, so it had to be my fault.
    I looked at the 0809 file I downloaded and the content was blank. So the file was being applied but there was no mapping! D'oh!!!

    Tried it all again and it is now working. Bob on!
    Thanks a lot.

  17. This comment has been removed by the author.

  18. Hi,

    I have found that the XRDP keyboard layout problem is unsolvable the "easy" way, as things sometimes can be in Linux.

    Fortunately, there is a workaround, as there is often in Linux.

    Here is a guide I wrote:


  19. I spent hours thinking it was the mapping on the OS before the light went on that maybe my issue was due to the fact that I was using xrdp - followed your steps problem solved - awesome!

  20. Excellent, thanks for posting this.

  21. Many thanks for taking the time to create the file, and make it available.

  22. Brilliant, worked a treat and fairly easy for a noob to follow.
    Thank you.

  23. I'm a Raspbian new user and when I try to save the ini fiile in the xrdp folder or copy it over I get permission denied. How do I change the permissions to allow this?

    1. In case anyone else has this problem I managed to change the permissions with a bit of help from google...
      "sudo chmod -R ugo+rw /etc/xrdp"

      Keyboard re-map working great. Thanks.

    2. IMO, one should not "solve" any problem by "opening up" everything to everyone. Even for raspbian, one should think in terms of "admin" functions and "user" functions. I would suggest applying "sudo" to whichever command is being used to save the .ini file in the xrdp folder, rather than changing permissions. That could save you accidentally "blowing away" something in future.
      p.s. a (all) is shorthand for ugo, as in a+rw

  24. Thank you. This worked for me now with a Norwegian keyboard layout. I followed the following steps:
    1. downloaded the ini file that is attatched in the first message from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=709588
    2. Saved the file as /etc/xrdp/km-0414.ini
    3. Did sudo chown xrdp /etc/xrdp/km-0414.ini
    4. Did sudo chgrp xrdp /etc/xrdp/km-0414.ini
    5. Rebooted the Raspberry pi and the norwegian keyboard over RDP worked as it should!

    Regards, Eirik

  25. Wicked - nice easy little fix


  26. Thank you for sharing this

  27. Pull request created: https://github.com/neutrinolabs/xrdp/pull/416

    Does anybody have any suggestions? Robin, did I credit you properly?

  28. ACE! Just saved me hours of work! Works a treat :-)

  29. Superb!
    If you're a noob like me. Download the file and right click on the folder its located in and click 'Open in Terminal'
    in the terminal type
    sudo cp km-0809.ini /etc/xrdp/
    Then you can enter the commands above.

  30. Thank you for this it was driving me insane but your solution just worked