I have been wracking my brain over the past week or so with what should be a straight forward problem. I want to permanently swap the CapsLock and Ctrl keys on my laptop. I emphasise the permanently because I know how to do this on an ad hoc basis easily from the command line with a minor tweak to the keyboard map:

setxkbmap -option ctrl:swapcaps

The problem with this is I have to execute it every time I boot up, wake from sleep/hibernate, or connect a USB keyboard. This quickly gets annoying, and this really feels like something that should be persistently set on a per user basis.

After extensive Google searching and on this forum, I have drawn up the following dead ends:

  1. Setting a "Startup Application" with the appropriate command works for initial login, but then the keyboard gets reset upon sleep/hibernate and USB keyboard connection. This is the solution I see posted everywhere, but its not really a solution. Example: https://ubuntuforums.org/showthread.php?t=2375159&highlight=keyboard+map

  2. I dove into X11/Xorg configuration. Creating any version of .x<something> in my home directory has no efffect (e.g. ~/.xinitrc, ~/.Xkbmap, ~/.Xmodmap, ~/.profile)

  3. Tried placing a script in /etc/X11/xorg.conf.d/ but that has no effect either.
  4. I don't have a /etc/X11/xorg.conf file present and I don't particularly want to generate one. Also, I would rather not make a setting that is universal across users and not portable across devices. It seems like the above doesn't work because of gdm3 taking over the Xsession generation and possibly some involvement of Wayland (although I have confirmed my user session is X11 and not Wayland). I looked at the file /etc/gdm3/Xsession and confirmed that it does source the ~/.x<something> files, but then those settings must get overwritten at some point.

I have also come across this answer, but I can't tell if it will remap permanently, and it seems like a much more complicated way to achieve what I have with one line above.

Does anyone have any insight through this swamp? It seems like the desktop/display manager situation for Ubuntu is an absolute mess with no definitive documentation.

My system: 5.3.0-28-generic #30~18.04.1-Ubuntu SMP Fri Jan 17 06:14:09 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

1 Answer 1


Why not simply edit the /etc/default/keyboard file and include the line:



A user specific equivalent would be:

  • Install gnome-tweaks

    sudo apt install gnome-tweaks
  • Open Tweaks

  • Navigate to Keyboard & Mouse -> Additional Layout Options -> Ctrl position

  • Select Swap Ctrl and Caps Lock

Edit II:

A command line way to achieve the latter:

gsettings set org.gnome.desktop.input-sources xkb-options "['ctrl:swapcaps']"
  • This is the first thing I have found that works, which is certainly an achievement and better than the alternative. However, it doesn't satisfy my desire to find a solution that is user specific and so doesn't alter system files.
    – BielsNohr
    Feb 19, 2020 at 9:00
  • Out of curiosity @Gunnar Hjalmarsson where is it documented that this is an option for altering keyboard configuration?
    – BielsNohr
    Feb 19, 2020 at 9:07
  • @BielsNohr: Please see my edited answer. As regards documentation of this kind of change, it leaves a bit to be desired, I'm afraid. Ask Ubuntu and other similar resources compensate for that. Feb 19, 2020 at 14:17
  • Presumably I can also alter that setting from the command line? I want to have a bash script I can run whenever I'm on a new machine that does this modification (along with other configurations).
    – BielsNohr
    Feb 20, 2020 at 15:46
  • @BielsNohr: I edited the answer again. Feb 20, 2020 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .