Change caps-lock to control in virtual console on Ubuntu 17

I'd like to change the Caps Lock behavior in virtual terminals (tty e.g. CtrlAltF3) so it acts as a Control modifier. Ideally, I'd also like it to act as Escape when pressed alone, but just getting the Control behavior is proving difficult.

I'm running Ubuntu 17.04. I've read and tried numerous approaches to making this change, but none seem to apply to my system as described. I get the sense that systemd plays a part in this, but the particulars are unclear.

I've written a file, caps_control.kmap, that maps caps to control,

keymaps 0-255
keycode  58 = Control

If I run loadkeys caps_control.kmap from a virtual console, it works. Now I'd like to get it to load automatically upon boot/login/whatever...

I found references to using /etc/rc.local to do so, but my system has no such file, though it does have several directories like /etc/rc0.d/, /etc/rc1.d/, ...

It sounds like since Ubuntu 17 uses sytemd, I should use localectl to manage this sort of thing, but it's not clear to me how to do so. For example,

$ localectl status
   System Locale: LANG=en_US.UTF-8
       VC Keymap: n/a
      X11 Layout: us
       X11 Model: pc105
$ localectl list-keymaps
Couldn't find any console keymaps.

The man page for localectl mentions /etc/locale.conf and /etc/vconsole.conf, neither of which exist on my system.

I am totally at a loss. Can anyone point me in the right direction?


To turn Caps Lock into an additional Ctrl modifier, which is also effective in tty consoles, open /etc/default/keyboard for editing and set:

XKBOPTIONS=ctrl:nocaps

If you already have XKBOPTIONS set, append ctrl:nocaps to its existing value using a comma for separator, e.g.:

XKBOPTIONS="terminate:ctrl_alt_bksp,ctrl:nocaps"

Should be effective after next reboot or issuing the setupcon command.

The option should be present when running localectl status:

$ localectl status | grep caps
     X11 Options: ctrl:nocaps

And in the X session, another way to verify that it's set is:

$ gsettings get org.gnome.desktop.input-sources xkb-options
['ctrl:nocaps']