Remote desktop to Ubuntu has wrong keyboard mapping

Solution 1:

I have exactly the same problem when connecting to a remote instance on AWS. It seems to be related to xrdp. See for instance this thread, which describes a detailed work-around.

EDIT: Took me a while to get back to this, but since there has been no further activity in this thread, I finally got around to add details as suggested (demanded?) in the comments.

These are the steps I had to do to fix the keyboard layout in xrdp in Ubuntu 12.04. The original link was a big help, but a bit out-dated. I also found useful information with the rdesktop project, for finding country codes: here and here.

  1. Open console and set xkb map to correct model & layout.

    setxkbmap -model pc105 -layout no
    

    Replace model and layout language code to whatever is the correct one for you. I just ran setxkbmap -print on the client PC (which incidently also runs Ubuntu 12.04) to get an idea about these values. Note that setxkbmap needs to have a display to run. You can either run the console through a RDP session or perhaps even login through ssh with X display redirection, like this ssh -X <server>.

  2. Generate XRDP keymap file:

    xrdp-genkeymap km-0414.ini
    sudo mv km-0414.ini /etc/xrdp
    sudo chown root:root /etc/xrdp/km-0414.ini
    

    Replace the country code 0414 with the correct code for your country. See the rdesktop doc to find the correct code for you.

  3. Restart the xrdp service:

    sudo service xrdp restart
    

Solution 2:

I had the same problem, and in my case, just running:

setxkbmap 

without any option, fixed the issue

Solution 3:

I've been fighting this for over a year, it turned out the solution was easy. Until this if I typed asdf I got abfh in some X apps, the occasional few would work just fine.

Uninstall tightvncserver and install vnc4server (you probably also want to do the same with the viewers). Viola, problem disappeared.

Solution 4:

Also had this problem but fixed it by running the following command in the console:

setxkbmap ua

This is for the ukrainian keyboard mapping. Select the language that is present on your keyboard. My keyboard is connected via VNC. It also works on CentOS 7. The answer was found here: https://askubuntu.com/a/580428/644928

UPDATE Not working special characters such as "# @". The following command helped:

setxkbmap ua -model pc105

UPDATE I use Windows RealVNC to connect to the СentOS. Centos are only set to English. Windows has Ukrainian and English. The language switches only in Windows and it passed to Linux. The problem with the language/keyboard mapping was until i changed to remote control on linux from TigerVNC to TurboVNC.

Solution 5:

I'm a bit of a newbie so this may only be relevant for later versions of Ubuntu (I'm on 17.04) or perhaps XOrg/Xfce but the solutions by seb and Steinar only worked temporarily for me, as soon as I logged out then back into an RDP session the keyboard would reset to US.

I found the solution at the bottom of this Getting x11rdp working on Debian 8 while targeting Debian worked for me (you may need to sudo as necessary):

wget https://www.dropbox.com/s/rtxp19ts17k8qy8/km-0809.ini
cp km-0809.ini /etc/xrdp/

sed -i '/\[default_rdp_layouts\]/a rdp_layout_gb=0x00000809' /etc/xrdp/xrdp_keyboard.ini

sed -i '/\[default_layouts_map\]/a rdp_layout_gb=gb' /etc/xrdp/xrdp_keyboard.ini

Now each time I log in, keyboard is set to en-gb and " and @ work as expected.