Recently, I tried to switch capslock and ctrl on my Ubuntu 18.04. I did it by add the following line into my .bashrc:

# swap capslock and ctrl
/usr/bin/setxkbmap -option "ctrl:swapcaps"

This worked, but in an awkward way. Every time I logged in by GUI, I need to start a new terminal to activate this setting. And sometimes when I locked the desktop and then logged in back, this setting is deactivated and I had to source .bashrc to activate it again.

I wanted to find a way to activate this setting automatically upon my logging in by GUI. I searched around and find that there are log-in bash and non-log-in bash. I believe when I logged in by GUI, I actually started a log-in bash. So I put my setting in ~/.profile. But it did not even work any more!

So is there any approach to automating the activating of the setting? And what happened when I logged in by GUI? I mean, if it does not start a log-in bash, how could I start other application on GUI?


Place this in file /etc/X11/xorg.conf.d/50-keyboard.conf for example:

Section "InputClass"
  Identifier "my laptop keyboard"
  MatchIsKeyboard "on"
  MatchProduct "AT Translated Set 2"
  #  Option "XkbModel" "asus_laptop"
  #  Option "XkbLayout" "us"
  Option "XkbOptions" "caps:none"

Be sure to change the MatchProduct to your own if that doesn't work. Look in Xorg.0.log for the product name.

The XkbModel and XkbLayout are optional so can be automatically selected by Xorg defaults or customized.

The XkbOptions is where you put your options to swap the keys or turn off CapsLock as I have done.

Reference: "man xkeyboard-config"

EDIT: I have Debian installed on several of my machines while I now prefer voidlinux. I think the xorg.conf is about the same for Ubuntu.

Create the directory /etc/X11/xorg.conf.d if that does not exist. See the xorg.conf man page for details.

The common way to modify the Xorg is by placing your own config files in /etc/X11/xorg.conf.d/ and making sure they are used instead of the automatic config files in /usr/share/X11/xorg.conf.d/ by checking the /var/log/Xorg.0.log file.

  • There is no xorg.conf.d directory under /etc/X11 path at all. Are you sure you are using Ubuntu 18.04? – Rivers Shall Dec 30 '18 at 3:15
  • The /etc/X11/xorg.conf.d directory should be created if not found. I edited my above answer with more information. – beginner6789 Dec 30 '18 at 12:51

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.