Inspect Linux Console Scancode Mappings with getkeycodes
A key that works on one virtual console and does nothing on another is exactly what getkeycodes exists to diagnose. It prints the kernel's current scancode-to-keycode table for the active console, a read-only check that never changes a mapping.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about five minutes. You need the kbd package and a local Linux virtual terminal, such as /dev/tty1 through /dev/tty63. An SSH shell, terminal emulator, container or graphical desktop terminal is not automatically a virtual console.
1. Check the Installed Command
Run the version check as your ordinary user; it is harmless and needs no sudo:
getkeycodes --version
On the machine used for this guide, the installed output is:
getkeycodes from kbd 2.6.4
The package version there is kbd 2.6.4-2ubuntu2. Your distribution may package a different release. The local manual page describes the plain command as taking no options at all, but this installed 2.6.4 binary also accepts --version: treat the output from your own binary as authoritative on that point.
Checkpoint
Continue once getkeycodes --version prints a kbd version. If the shell says the command is not found, install the kbd package through your normal package manager, and confirm the package name and repository first since installing changes system state.
2. Run the Mapping Query from a Virtual Console
Switch to a Linux virtual terminal with Ctrl+Alt+F3, or whichever function key your system uses. Log in, then run:
getkeycodes
- No arguments needed. The command takes none.
- Two ranges printed. A formatted table lists plain scancodes in hexadecimal with their keycodes in decimal, followed by the escaped
e0scancode range. - Kernel-supplied values. The exact numbers depend on the active console and the kernel's keyboard support.
- Low range is regular. Scancodes 1 through 88 normally map to the same keycode; later entries are queried live from the kernel, and a dash means an entry was not available.
Read the table as an observation of the console mapping only, not as a translation table for X11, Wayland, USB HID usage codes, or any application-specific input library.
Tip
Save the output before comparing a working and a failing console. Redirection does not touch the keyboard, but it creates or replaces the named file, so pick a new path or a file you know is disposable:
getkeycodes > /tmp/getkeycodes-before.txt
sed -n '1,12p' /tmp/getkeycodes-before.txt
Do not treat that saved file as a configuration file; feeding it to another command will not restore a mapping. The related setkeycodes(8) command changes the kernel mapping and carries a separate syntax and risk profile.
3. Handle the Console Error Correctly
Run the command from SSH or a graphical terminal and you may see this instead of a table:
Couldn't get a file descriptor referring to the console.
That means the program could not get a usable Linux console device in that session. It is not evidence the keyboard has an empty mapping. Repeat the test from a local virtual terminal, or an administrative recovery console that genuinely exposes one.
Running the same command with sudo only helps if permissions were the actual problem. It cannot turn an SSH pseudo-terminal or a container's standard input into a virtual console:
sudo getkeycodes
Use elevated privileges only when your system's device permissions require them; the command reads the mapping and never needs to modify files or restart a service. If it still reports the console error under sudo, stop retrying it there and move to a real virtual terminal.
4. Compare a Suspicious Key Without Changing the Mapping
Capture the table on a console where the key behaves, then on the console where it fails:
getkeycodes > /tmp/getkeycodes-working.txt
getkeycodes > /tmp/getkeycodes-failing.txt
diff -u /tmp/getkeycodes-working.txt /tmp/getkeycodes-failing.txt
Identical tables from the same kernel and console state suggest the fault sits elsewhere: check the program's input path, the desktop input stack, the keyboard layout, or the device's event stream. A changed table is evidence of different kernel console state, but it does not by itself identify which command or service caused the change.
Warning
Do not use setkeycodes as an experiment on a remote machine. It changes keyboard behaviour and can make recovery awkward if the affected key is the one you need to switch consoles or log back in. If you deliberately change a mapping later, record the original table first and keep a tested out-of-band access method.
Done means
- Version checked.
getkeycodes --versionidentified the installed kbd release, where supported. - Ran from the right place.
getkeycodesran from a Linux virtual console, or the console-only failure was correctly identified. - Table read correctly. You treated it as kernel console data, not an X11, Wayland, USB HID or application mapping.
- Comparisons saved sensibly. Any comparison files went to an intentional temporary path.
- Nothing changed. No mapping was touched, and any later
setkeycodes(8)work has its own backup and recovery plan.