brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: localectl set-keymap changes the console and X11 keyboard layout together

Linux
~/tips/tip-linux-localectl-set-keymap

sudo localectl set-keymap us

Sets the system keyboard mapping for the console and X11 in one command.

A server console with the wrong keyboard layout is a special kind of annoying, because the characters you need for a password are the ones that moved. localectl can fix that without editing files by hand.

localectl list-keymaps
sudo localectl set-keymap us

The first command lists the keymaps available for the console. The second sets the system keyboard mapping. Per the localectl man page, unless you pass --no-convert, the choice is also applied as the default X11 mapping. So one command covers both the text console and a graphical session that reads the system default.

It works the other way around too. localectl set-x11-keymap LAYOUT [MODEL [VARIANT [OPTIONS]]] sets the X11 default and, again unless you pass --no-convert, applies it to the virtual console as well.

sudo localectl --no-convert set-keymap us

That version changes only the console and leaves the X11 default alone. I’d use it when the two should differ, for example a machine where the console is used rarely and the desktop layout was set up on purpose.

To see what is set right now, run localectl status. It shows the current system locale and keyboard mapping.

Two caveats. The man page says localectl talks to systemd-localed, which writes files such as /etc/locale.conf and /etc/vconsole.conf, so this is a system-wide setting and not a per-user one. This tip follows the documentation and was not run against a live system.

Further reading: localectl(1) man page

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Linux tips notify-send -r "$id" "Backup" "Done" pgrep -af 'sleep 301' smbstatus -L msmtp --serverinfo --tls --tls-certcheck=off --host=smtp.example.com --port=587 smbclient //server/share -U user -Tc backup.tar "*" All Linux tips (283) All topics

Link