I recently installed Debian 9 and inserted my usual ~/.Xmodmap file and added xmodmap ~/.Xmodmap to my .xsession. To my disappointment this didn't actually work.

For reference, I run i3 from startx without a DM.

To test if the command ran successfully I replaced the command in my .xsession with touch ~/prior && xmodmap ~/.Xmodmap && touch ~/post. And the files were in fact created indicating that the xmodmap command was indeed ran correctly but the mappings were reset somewhere, probably by a call to setxkbmap.

I searched for a solution and found only questions without answers, or questions with old answers that didn't work for me, or that contained no real solution:


I found the cause of this behavior to be indirectly documented in man keyboard:


The keyboard file describes the properties of the keyboard. It is read by setupcon(1) in order to configure the keyboard on the console. In Debian systems the default keyboard layout is described in /etc/default/keyboard and it is shared between X and the console.

The contents of /etc/default/keyboard are generated on system install and gave a hint to the actual problem (I added the ctrl:nocaps option later):


The above together indicates that X will set the xkb options at some point during startup (probably after .xsession and the like) which causes any xmodmap settings set during .xsession to be lost.

So there is the cause, the solution is hinted at from man setupcon:

The keyboard configuration is specified in ~/.keyboard or /etc/default/keyboard. The font configuration is specified in ~/.console-setup or /etc/default/console-setup.

Checking man console-setup yields:

The file console-setup specifies the encoding and the font to be used by setupcon(1) in order to setup the console. It can be used also to specify the keyboard layout but it is not recommended to do so, use keyboard(5) instead.

So /etc/default/keyboard is used to set keyboard settings for TTY and X. While /etc/default/console-setup is can be used to setup keyboard (not really recommended but works) and font for console only.

So to make this all work I moved /etc/default/keyboard to /etc/default/console-setup and added the following to my .xsession:

# The below assumes bash features, rewrite if you use other shells.
source /etc/default/console-setup

if [[ "$XKBLAYOUT" ]]; then

if [[ "$XKBMODEL" ]]; then
    XKBPARMS+=" -model $XKBMODEL"

if [[ "$XKBVARIANT" ]]; then
    XKBPARMS+=" -variant $XKBVARIANT"

if [[ "$XKBOPTIONS" ]]; then
    XKBPARMS+=" -option $XKBOPTIONS"

if [[ "$XKBPARMS" ]]; then
    setxkbmap $XKBPARMS

xmodmap ~/.Xmodmap

Now xmodmap works correctly and I have the correct keymap and options in both the TTY and in X.

|improve this answer|||||

I was also having issues with xmodmap-type solutions, so after some research I decided to use xkb directly. I also found that the archwiki does not recommend xmodmap for anything but "the simplest" tasks:

Generally it is not recommended to use xmodmap, except maybe for the simplest tasks. XKB-compatible equivalent of xmodmap is xkbcomp; however, xkbcomp lacks -e option, so it is not that simple. Anyway, whenever possible, xkbcomp should be preferred.

The following solution worked for me (on Ubuntu 16.04):

  • In TTYs: how-to-change-console-keymap-in-linux.
  • In X: backup and modify the relevant files in /usr/share/X11/xkb/symbols/. I have changes in us (for number row and a few other things) and pc (for capslock).

Unfortunately, this does mean keeping track of two separate solutions for X and the TTY, but it's been alright with me so far.

But if you have an xmodmap solution that works already, that's all that matters!

|improve this answer|||||
  • Yes, I looked at xkb but it seemed way too complicated for the equivalent xmodmap. Specifically I remap right Ctrl to become Mod3 instead of functioning as a control modifier. This becomes my mod key for i3 which is easier to use on my hands than the Win which breaks my fingers and Alt conflicts with just about every other keybinding I use. But thanks for the comment, I'm sure it will be useful to someone who doesn't have a weird key rebinding schema. :) – Emily L. Nov 12 '17 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.