One Linux server at work has always messed up my keyboard mapping when connecting to it via VNC. Previously, I had worked around this issue by changing the window manager from gnome to evilwm in my ~/.vnc/xstartup
file. This got me by for a while, but I had trouble with the mask keys when I switched from Mac OSX Lion to Linux, so I came back to solving the problem. In my googling, I found this often-encountered situation referred to as the “abfh” problem1.
This post, and in particular, this comment provided the best solution I found for the “abfh” problem:
dcatdemon said... Perhaps you can try this: 1. edit your $HOME/.vnc/xstartup 2. put the line "export XKL_XMODMAP_DISABLE=1" before your gnome-session. 3. restart vncserver. and lo, it works :). credit must go to this link. http://bugs.gentoo.org/show_bug.cgi?id=190865#c7
There are many other possible solutions, but this seemed cleanest and simplest–and you gotta love a 1-liner.
Footnotes:
1 “abfh” refers to the output of pressing the standard key-mashing sequence “asdf”.