Remapping Modifier Keys on Linux
Remapping modifier keys on Linux makes sense if you’re an Emacs power user, prefer ergonomic hand positioning, or simply don’t use the Win key. The standard approach moves frequently-used modifiers closer to your thumbs by trading the underutilized Super/Win key for additional Ctrl or Alt access.
A typical remapped layout looks like:
|Ctrl|Alt|Ctrl| Space Bar |Ctrl|Menu|Ctrl|
Using xmodmap (X11 Only)
The traditional approach uses xmodmap, which reads key mapping definitions from a configuration file. This works only on X11 sessions, not Wayland.
Create ~/.Xmodmap:
! Swap left Alt and left Ctrl
keycode 64 = Control_L
keycode 37 = Alt_L
! Map Super (Win) to Alt
keycode 133 = Alt_L
! Map right Alt to Ctrl
keycode 108 = Control_L
Check your actual keycodes first:
xmodmap -pke | grep -E "(Alt|Control|Super)"
Apply changes immediately:
xmodmap ~/.Xmodmap
Verify the mapping worked:
xmodmap -pm
For X11 session persistence, add to ~/.xinitrc:
xmodmap ~/.Xmodmap
For display managers (GDM, LightDM, SDDM), create ~/.config/autostart/xmodmap-load.desktop:
[Desktop Entry]
Type=Application
Exec=xmodmap /home/yourusername/.Xmodmap
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Load Xmodmap
Using xkb (X11 and Better Wayland Support)
The xkb (X Keyboard Extension) approach is more robust and works better across modern systems. Create a custom symbols file at ~/.config/xkb/symbols/custom:
xkb_symbols "ctrl_alt_swap" {
replace key <LALT> { [ Control_L ] };
replace key <LCTL> { [ Alt_L ] };
replace key <RALT> { [ Control_L ] };
replace key <LWIN> { [ Alt_L ] };
};
Then load it with setxkbmap:
setxkbmap -I~/.config/xkb -symbols "pc+us+custom(ctrl_alt_swap)"
Test it works:
xkbcomp -xkb $DISPLAY -
For persistence, add the setxkbmap command to your session startup. On GNOME/systemd-based systems, create ~/.config/systemd/user/xkb-custom.service:
[Unit]
Description=Load custom xkb keymap
After=graphical-session-pre.target
PartOf=graphical-session.target
[Service]
Type=oneshot
ExecStart=%h/.config/xkb/load-xkb.sh
RemainAfterExit=yes
[Install]
WantedBy=graphical-session.target
Create the script ~/.config/xkb/load-xkb.sh:
#!/bin/bash
setxkbmap -I~/.config/xkb -symbols "pc+us+custom(ctrl_alt_swap)"
Make it executable:
chmod +x ~/.config/xkb/load-xkb.sh
Enable the service:
systemctl --user enable xkb-custom.service
GNOME Settings (GUI Approach)
Modern GNOME versions (42+) expose modifier key remapping through the Settings application:
- Open Settings → Keyboard
- Scroll down to Special Character Key Handling
- Remap Ctrl, Alt, and Super keys as needed
This GUI approach is easier but limited to GNOME’s supported remappings. It doesn’t handle all edge cases that xkb or xmodmap can.
KDE Plasma
KDE provides modifier key remapping through the system settings:
- Open System Settings → Input Devices → Keyboard
- Go to the Advanced tab
- Select Modifier Keys
- Configure your preferred layout
KDE persists these settings automatically.
Wayland Considerations
Wayland doesn’t use X11’s input system, so xmodmap doesn’t work. Check your session type:
echo $XDG_SESSION_TYPE
If it returns wayland, use one of these approaches:
- GNOME/KDE Settings (both have native Wayland support)
- Sway: Edit
~/.config/sway/configwithinput * xkb_options "ctrl:swap_lalt_lctl"and similar - Hyprland: Edit
~/.config/hyprland/hyprland.confwithinput { kb_options = ctrl:swap_lalt_lctl } - Systemd user service with setxkbmap if your Wayland compositor supports XWayland
Troubleshooting
Remapping doesn’t persist after logout:
- Verify the startup script/service is enabled:
systemctl --user list-unit-files | grep xkb - Check file permissions:
ls -la ~/.Xmodmap ~/.config/xkb/load-xkb.sh - Review logs:
journalctl --user -u xkb-custom.service
Keys feel unresponsive or mapped incorrectly:
- Reload the keymap:
setxkbmap -I~/.config/xkb -symbols "pc+us+custom(ctrl_alt_swap)" - Test in a terminal:
xevshows keycodes and current mappings - Restart your session (logout/login) if changes don’t apply
Conflicting with application-level bindings:
- Emacs users should verify
M-xandC-xwork correctly - Some applications (browsers, terminals) may have hardcoded Alt behavior—test in your primary use cases
- If conflicts occur, adjust your xkb symbols file rather than relying on application settings
Partial remapping not working:
- Keycodes vary by keyboard layout and hardware—always run
xmodmap -pketo find your actual keycodes - Some laptop keyboards have special firmware-level key handling that bypasses userspace remapping
Test your final configuration in Emacs, your terminal, and text editor before considering it production-ready.

I wonder how you are using Gnome 3 but not using the Windows key. That is by far the most useful key when you’re using Gnome :P