How To Disable Caps Lock Key in Linux using CLI or GUI

How do I deactivate or disable caps lock key in Linux permanently?

You need to use the xmodmap command. It is used to edit and display the keyboard modifier map and keymap table that are used by client applications to convert event keycodes into keysyms. It is usually run from the user’s session startup script to configure the keyboard according to personal tastes.You can also use the setxkbmap command that maps the keyboard to use the layout determined by the options specified on the command line. This page explains how to disable Caps lock key in Linux using the command-line options.

How to use xmodmap command to turn off caps key

To turn off caps lock key, enter:
$ xmodmap -e "remove lock = Caps_Lock"
Now caps key is disabled. To enable caps key, enter:
$ xmodmap -e "add lock = Caps_Lock"
Add following code to your shell startup file ~/.bash_profile or ~/.profile file:
$ echo 'xmodmap -e "remove lock = Caps_Lock"' >> ~/.bash_profile

setxkbmap command to turn off caps locks key

You can also use the setxkbmap command, which maps the keyboard to use the layout determined by the options specified on the command line. To turn off caps lock key, enter:
$ setxkbmap -option ctrl:nocaps
To reset caps lock. enter:
$ setxkbmap -option

Disabling the caps lock key in the command line using xdotool

First, install xdotool using the dnf command/zypper command or apt command as per your distro. For example:
$ sudo apt install xdotool
Then we can toggle Caps Lock using the following command:
xdotool key Caps_Lock
Please note that we rerun the above command to go back to the previous state. In other words, type:
xdotool key Caps_Lock

A note about a virtual terminal

We can use the following command turn on caps:
setleds -D +caps
Then turn caps back off if required:
setleds -D -caps
The -caps or +caps option clear or set CapsLock when using VT.

How to deactivate Caps Lock in Linux using gnome-tweaks

You need to use GNOME Tweak Tool. It allows the adjustment of several advanced GNOME options that can’t be configured in gnome-control-center. Install it using the apt command/apt-get command:
sudo apt install gnome-tweaks
And then start it:
gnome-tweaks

Click on the Keyboard & Mouse > Additional Layout Option:

Set up Caps Lock behaviour as per your needs.

Summing up

You learned various commands and GUI tools to set up cap lock key settings on a Linux desktop. Further readings:
man setxkbmap
man xmodmap
man setleds


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • housetier Oct 22, 2008 @ 14:35

    I have switched ESC and CAPS_LOCK, which makes vim much easier to use.

  • Gokdeniz Karadag Oct 22, 2008 @ 17:51

    Making caps lock an additional control key is ver useful also. It makes typing shortcuts a lot easier.

  • lowly worm Mar 6, 2009 @ 19:33

    I want to disable a bunch of keys because my daughter accidently presses them when she is playing a game on her “Aspire one”. The method worked for many keys but not all.

    For example to disable the tux-key (the linux equivilent to the windows-key)
    xev doesn’t show a keycode when i press the tux key
    infact i don’t see any Keypress event, just a lot of other events.

    ———————————————————————————
    [user@localhost ~]$ xmodmap -pm
    xmodmap: up to 3 keys per modifier, (keycodes in parentheses):

    shift Shift_L (0x32), Shift_R (0x3e)
    lock Caps_Lock (0x42)
    control Control_L (0x25), Control_R (0x6d)
    mod1 Alt_L (0x40), Meta_L (0x9c)
    mod2 Num_Lock (0x4d)
    mod3
    mod4 Super_L (0x7f), Hyper_L (0x80)
    mod5 Mode_switch (0x5d), ISO_Level3_Shift (0x71), ISO_Level3_Shift (0x7c)
    ———————————————————————————————

    I thought it might be possible to just remove the mapping for “mod4 Super_L”, but even that did not work.

    Any tips on this, most welcome.
    //The Lowley Worm

  • Jasleen May 10, 2009 @ 13:19

    I think, that the command

    xmodmap -e “remove lock = Caps_Lock”

    only works if your caps lock is off

  • Pradeep Aug 23, 2009 @ 13:42

    How Can I Disable the Keyboard in RHEL-4.
    to Aovid the Input In My Absens.
    Pradeep

  • Tucker Oct 22, 2009 @ 22:14

    @Pradeep

    Maybe try lock screen?

  • Ton Aug 18, 2012 @ 6:41

    xmodmap -e “remove lock = Caps_Lock” is my favorite command to add as ´startup application´ :)

  • Hans Linkels Oct 15, 2012 @ 20:18

    xmodmap -e “remove lock = Caps_Lock” works as a charm, but when you replug the USB keyboard caps lock is functional again.
    I use this to discourage my son of typing caps-lock-on-character-caps-lock-off. This sounds very unusual, yet I discovered there are more people who have developed this unwanted habit.
    As it seems, I should link the xmodmap command to a udev event.

    jlinkels

  • Pencioner Jan 23, 2013 @ 9:18

    Hey you saved me a reboot :) Well, i sometimes getting into trouble with x11vnc with my X keyboard configuration (grp:ctrl_shift_toggle,grp:shift_caps_switch,grp_led:num) – leaving me with LOCKED CAPS when i just pushed it to switch back to english when connected via VNC. Btw, running ‘setxkbmap -option’ to reset this behaviour to default, turn off annoying caps lock, and then setxkbmap -option with the above line from xorg.conf resolves the deal. and this happened few times before – i needed reboot. Thank You ;)

  • Ralph Quinn Jun 6, 2021 @ 18:46

    Command did worked but I discoverd “Gnome Tweaks” tool. Thank you, mate.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum