Keyboard layouts and the Linux console: localectl, loadkeys, XKB

Updated November 2026

Linux has two separate keyboard systems: the kernel's console keymap, used on the text consoles (/dev/tty1–tty6), and XKB, used by X11 and every Wayland desktop. localectl sets both on most distributions; Debian and Ubuntu use one shared file, /etc/default/keyboard. This page shows how to set layouts, remap keys, add a Compose key and change the console font.

Commands are for current Debian, Ubuntu, Fedora, RHEL-family, Arch and openSUSE systems as of November 2026. The classic version of this HOWTO, which described Linux 2.0, is kept by the LDP at tldp.org.

Two keyboard paths

Keyboard(kernel keycodes) Console keymaploadkeys, vconsole.conf Text consoles libinput + XKBlayout, variant, options Wayland compositoror Xorg, then apps
The text console and the graphical session translate keycodes separately, so each needs its own layout setting.

Because the paths are separate, a layout chosen in GNOME Settings does not change the text console, and loadkeys does not change your desktop. localectl and Debian's keyboard-configuration exist to keep the two in step.

See the current settings

localectl status

On a US-layout system the output looks like this:

System Locale: LANG=en_US.UTF-8
    VC Keymap: us
   X11 Layout: us
    X11 Model: pc105

VC Keymap is the console keymap; the X11 lines are the XKB defaults that display managers and new desktop users start with. (The name says X11, but Wayland desktops read the same values.)

Set the layout system-wide

Fedora, RHEL family, Arch, openSUSE

localectl list-keymaps | grep -i de             # find console keymap names
sudo localectl set-keymap de-latin1             # console; also sets the closest X11 layout
sudo localectl set-x11-keymap de pc105 nodeadkeys ctrl:nocaps   # layout, model, variant, options

set-keymap writes KEYMAP= to /etc/vconsole.conf and, unless you add --no-convert, also sets the nearest X11 layout. set-x11-keymap works the other way round. Use localectl list-x11-keymap-layouts, list-x11-keymap-variants de and list-x11-keymap-options to see valid names. A typical /etc/vconsole.conf:

KEYMAP=de-latin1
FONT=eurlatgr

Debian and Ubuntu

Debian and Ubuntu describe the keyboard once, in XKB terms, in /etc/default/keyboard; the console-setup package converts it for the console. (On Debian 13, /etc/vconsole.conf may simply be a link to this file.) Change it with the menu-driven tool or by editing the file:

sudo dpkg-reconfigure keyboard-configuration
# /etc/default/keyboard
XKBMODEL="pc105"
XKBLAYOUT="us,de"
XKBVARIANT=","
XKBOPTIONS="grp:alt_shift_toggle,ctrl:nocaps"
BACKSPACE="guess"

Apply it to the console with sudo setupcon. The graphical side picks the change up after a reboot, or after sudo udevadm trigger --subsystem-match=input --action=change. Here Alt+Shift switches between US and German, and Caps Lock becomes an extra Ctrl, on the console and the desktop alike.

Useful XKB options

XKB options from /usr/share/X11/xkb/rules/base.lst
OptionEffect
ctrl:nocapsCaps Lock as Ctrl
ctrl:swapcapsswap Ctrl and Caps Lock
caps:escapeCaps Lock as an extra Esc
caps:swapescapeswap Esc and Caps Lock
compose:ralt, compose:menuRight Alt or Menu key as Compose
grp:alt_shift_toggle, grp:win_space_toggleswitch layouts with Alt+Shift or Win+Space

Combine options with commas. grep -E 'ctrl:|caps:|compose:|grp:' /usr/share/X11/xkb/rules/base.lst lists them all.

Desktop layouts on Wayland and X11

Desktop environments keep their own per-user layout list, which overrides the system default once you log in.

The Compose key

A Compose key lets you type characters your layout lacks by pressing a short sequence: Compose, then ', then e gives é; Compose " u gives ü; Compose - - - gives an em dash (—). Enable it with the option compose:ralt (or compose:menu), or in GNOME under Settings, Keyboard, Compose Key. In GNOME you can also type any character by its code point: Ctrl+Shift+U, the hex code (for example 20ac for €), then Space. For locales and UTF-8 in general, see the Unicode HOWTO.

Console-only keymaps with loadkeys

To try a console keymap without making it permanent, switch to a text console and run:

sudo loadkeys de-latin1      # until the next reboot or loadkeys
sudo loadkeys us             # back to US

To remap single keys, find their keycodes with sudo showkey -k on a text console (it exits 10 seconds after the last key). Caps Lock is usually keycode 58 and Esc keycode 1. Write only the changes to a file:

# /usr/local/share/kbd/keymaps/personal.map
keycode 58 = Control       # Caps Lock becomes Ctrl
# or swap Caps Lock and Esc instead:
# keycode 1 = Caps_Lock
# keycode 58 = Escape

sudo loadkeys /usr/local/share/kbd/keymaps/personal.map applies it on top of the current keymap. To load it at boot on systemd distributions, put the full path in KEYMAP= in /etc/vconsole.conf; that works directly for a US layout, because the kernel's built-in keymap is US. For another layout, copy your layout's full keymap file (localectl list-keymaps shows the names; Arch keeps the files under /usr/share/kbd/keymaps) and edit the copy. On Debian and Ubuntu, use XKBOPTIONS as shown above instead. sudo dumpkeys prints the active keymap.

Console fonts

On high-resolution screens the default console font can be tiny. setfont changes the font of the console you are on:

setfont ter-132b          # Terminus, 32 pixels high, bold (needs the Terminus console fonts)
setfont                   # back to the default font

setfont -d FONT doubles a smaller font pixel for pixel, which suits 4K screens.

Make it permanent with FONT=ter-132b in /etc/vconsole.conf (systemd distributions such as Fedora, Arch and openSUSE; on Arch the fonts come from the terminus-font package). On Debian and Ubuntu run sudo dpkg-reconfigure console-setup, or set FONTFACE="Terminus" and FONTSIZE="16x32" in /etc/default/console-setup and run sudo setupcon. Fonts live in /usr/share/kbd/consolefonts on Arch, /usr/lib/kbd/consolefonts on Fedora and /usr/share/consolefonts on Debian. The console and framebuffer HOWTO covers console resolution.

Virtual consoles

Ctrl+Alt+Del and SysRq

On a text console, Ctrl+Alt+Del makes systemd start ctrl-alt-del.target, which normally means a clean reboot. To disable it on a server where an accidental press would hurt:

sudo systemctl mask ctrl-alt-del.target

Pressing it more than 7 times within 2 seconds still forces a reboot unless you set CtrlAltDelBurstAction=none in the [Manager] section of /etc/systemd/system.conf.

The Magic SysRq key talks directly to the kernel and works even when the system seems frozen. On x86 press Alt+SysRq (Print Screen) plus a letter: s syncs disks, u remounts filesystems read-only, b reboots immediately. /proc/sys/kernel/sysrq controls which functions the keyboard may use: 0 disables SysRq, 1 enables everything, and larger numbers are a bitmask (16 sync, 32 remount read-only, 128 reboot and power off). Check and change it:

cat /proc/sys/kernel/sysrq
echo 'kernel.sysrq = 176' | sudo tee /etc/sysctl.d/90-sysrq.conf   # 16 + 32 + 128
sudo sysctl --system

Key repeat and Backspace

On the console, sudo kbdrate -d 250 -r 30 sets a 250 ms delay and 30 characters per second; desktop sessions have their own setting under keyboard settings. If Backspace sends the wrong code in a terminal program, see stty erase in the terminal HOWTO; on Debian and Ubuntu the BACKSPACE setting in /etc/default/keyboard controls the console.

Sources