Getting Xorg to let you terminate the X server with Ctrl + Alt + Backspace

June 18, 2018

This is a saga. You can skip to the end for the actual answer if you're impatient.

Yesterday I wrote about the history of terminating the X server with Ctrl + Alt + Backspace. I've known about this feature for a long time, but I only wind up using it very occasionally, even for Cinnamon on my laptop. This infrequent usage explains how I only recently noticed that it had stopped working on my office machine. When I read the Xorg manpage for another reason recently, I stumbled over the current XKB mechanism. I decided to write a little entry about it, which I decided to save for a day when I was extra tired. Then I decided to do some research first, got some surprises, and wrote yesterday's entry instead.

My initial assumption about why C-A-B wasn't working for me was that the Xorg people had switched it off relatively recently (or changed some magic thing in how you had to turn it on). This 2010 SE question and its answers taught me otherwise; the switch had happened a very long time ago, and I was relatively certain that I had used C-A-B since then on my machines. So what had changed?

These days, the X server is mostly configured through configuration file snippets in a directory; on at least Fedora, this is /etc/X11/xorg.conf.d. In my office workstation's directory, I found a 00-keyboard.conf that dated from the start of 2015 and looked like this:

# Read and parsed by systemd-localed.
# It's probably wise not to edit this
# file manually too freely.
Section "InputClass"
   Identifier "system-keyboard"
   MatchIsKeyboard "on"
   Option "XkbLayout" "us"
   Option "XkbModel" "pc105+inet"
   Option "XkbVariant" "terminate:ctrl_alt_bksp,"
EndSection

I scanned this and said to myself 'well, it's setting the magic XKB option, so something else must be wrong'. I switched to using XKB back at the end of 2015, so at first I though that my setxkbmap usage was overwriting this. However inspection of the manpage told me that I was wrong (the settings are normally merged), and an almost identical 00-keyboard.conf on my home workstation worked with my normal setxkbmap. So yesterday I tiredly posted my history entry and muttered to myself.

This morning, with fresh eyes, I looked at this again and noticed the important thing: this file is setting the XKB keyboard variant, not the XKB options. It should actually be setting "XkbOptions", not "XkbVariant". Since there's no such keyboard variant, this actually did nothing except fool me. I might have noticed the issue if I'd run 'setxkbmap -query', but perhaps not.

All of this leads to the three ways to enable Ctrl + Alt + Backspace termination of the X server, at least on a systemd based system. First, as part of your X session startup you can run setxkbmap to specifically enable C-A-B, among any other XKB changes you're already making:

setxkbmap -option 'compose:rwin' -option 'ctrl:nocaps' -option 'terminate:ctrl_alt_bksp'

Second, you can manually create or edit a configuration file snippet in /etc/X11/xorg.conf.d or your equivalent to specify this. If you already have a 00-keyboard.conf or the equivalent, the option you want is:

Option "XkbOptions" "terminate:ctrl_alt_bksp"

(A trailing comma is okay, apparently.)

Third, if you have Fedora or perhaps any systemd-based distribution, you can configure this the official way by running localectl with a command like this:

localectl --no-convert set-x11-keymap us pc105+inet "" terminate:ctrl_alt_bksp

There is a bear trap lurking here. That innocent looking "" is very important, as covered in the Arch wiki page. As they write (with my emphasis):

To set a model, variant, or options, all preceeding fields need to be specified, but the preceding fields can be skipped by passing an empty string with "". [...]

Given that my original xorg.conf snippet had what should be the XKB options as the XKB variant, it seems very likely that back in January 2015, something ran localectl and left out that all important "".

(That I didn't really notice for a bit more than three years shows some mixture of how little I use C-A-B and how willing I am to shrug and ignore minor mysteries involving keyboards and X.)

My laptop had been set up and maintained as a stock Fedora machine; these days that apparently means that this option isn't enabled in the xorg.conf stuff. Unlike on my workstation (where I edited 00-keyboard.conf directly), I did it the official way through localectl. I determined the other command line parameters by looking at the existing 00-keyboard.conf; I believe that on the laptop, the model (the 'pc105+inet' bit) was blank, as was the variant.

Sidebar: How my machines got to their Xorg keyboard state

I assume that before that early 2015 change, my office workstation's Xorg configuration had the magic XkbOptions setting that made it work. I'm pretty sure that C-A-B worked at some point since 2010 or 2011 or so. My home machine has a 00-keyboard.conf from October 2011, which is about when I installed Fedora on it, with comments that say it was created by system-setup-keyboard, and that has the necessary XkbOptions setting. My office machine's Fedora install dates to 2006, so it might have had any number of configuration oddities that confused things at some point.

(My home machine got a completely new Fedora 15 install in 2011 as part of digging myself out of my Fedora 8 hole. My office workstation never got stuck on an older Fedora release the way my home machine did, so the Fedora install's never been rebuilt from scratch. Sometimes I get vaguely tempted by the idea of a from-scratch rebuild, but then I get terrified of how much picky work it would be just to get back to where I am now.)


Comments on this page:

My commiserations for whatever caused you to need it :).

I think if you move to Wayland, you will have to start using SaK. (Enable sysrq+k, or even the "proper" method described in "SAK.txt" does not seem too awkward). I guess in the old days SaK was undesirable and would leave you without a working text console, but we nowadays we have kernel modesetting to sort it out.

Written on 18 June 2018.
« The history of terminating the X server with Ctrl + Alt + Backspace
The time to be compatible with both Python 2 and Python 3 is past »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Mon Jun 18 23:11:47 2018
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.