I have scoured the web, and I can't seem to get Xmodmap / anything to work properly. I want to swap BOTH my Command keys with my Control key - in essence, inverting what they do currently.

How would I do that?

I tried xmodmap -e "keycode 133 = Control_L" and corresponding commands for keycodes 134 (right command) and 37 (control left). I even tried these commands, plus xmodmap -pke > ~/.Xmodmap and xmodmap ~/.Xmodmap in .xinitrc.

My end goal is I want HUD / Dash to come up when I click control and command to functional control, i.e., control-v is a commond shortcut to paste, i would click command-v


I figured it out. Put the following in ~/.Xmodmap:

clear control
clear mod4

keycode 105 =
keycode 206 =

keycode 133 = Control_L NoSymbol Control_L
keycode 134 = Control_R NoSymbol Control_R
keycode 37 = Super_L NoSymbol Super_L

add control = Control_L
add control = Control_R
add mod4 = Super_L

To test, run the command:

xmodmap ~/.Xmodmap

To make it run every time, add it to Startup Applications.

This should work on any MacBook Pro; the issue was that Xmodmap was assigning Super_L to the left and right command keys, and Control_L to the left control key. For some reason, by default, Ubuntu thinks that the MacBook Pro has a standard 105 key keyboard (probably thinking about the full Apple Keyboard) but that is wrong. Anyway, I reassigned the keycodes to the right keysims, then assigned the keysims to control and mod4.

  • I have an extra question: how can I change the left Control key to become the alt key, and viceversa, the alt key next to the left Control key to become the left Control key? – 719016 Jun 1 '15 at 15:45
  • how do I keep the right hand side win button working? – arcanine Jun 24 '16 at 12:40
  • Mind that this does not work well with keyboard layout switching. So if you use more than one layout, you'll have to run xmodmap after every layout change. Answer below that suggests editing /usr/share/X11/xkb/symbols/pc is immune to that. – clorz May 1 '17 at 6:59

I just installed Ubuntu 16.04 dual boot on my MBP13" yesterday. For Ubuntu 16.04, here's how i did it:

Step 1: Launch terminal

Step 2: Edit X Keyboard Extension

sudo nano /usr/share/X11/xkb/symbols/pc

Step 3: Make the following changes. Ensure your file looks like this:

key <LCTL> {    [ Super_L       ]   };
key <LWIN> {    [ Control_L     ]   };


key <RCTL> {    [ Super_R       ]   };
key <RWIN> {    [ Control_R     ]   };

Step 4: Clear xkb's cache

sudo rm -rf /var/lib/xkb/*

Step 5 (conditional): If the keys are not swapped after step 4, restart your computer. It worked for me after this.

Hope it helps, good luck!

  • This is a much better solution than the accepted answer. – Mr Axilus Oct 22 '16 at 15:42
  • Did not work for me. – chovy Dec 18 '16 at 5:24
  • This is the actual(2017) answer. – CESCO Feb 16 '17 at 11:55
  • This is the answer. Needs restarting after change. Thanks – lxm7 Sep 17 '17 at 8:34
  • This worked for me! Finally switching between Mac OS and Linux doesn't involve nearly as much muscle memory reprogramming :) – JoLoCo Jan 4 '18 at 17:45

Go into System -> Preferences -> Keyboard

Click on the "Layouts" tab and then click the "Layout Options" button.

Click on "Alt/Win key behavior"

Select "Control is mapped to Win keys (and the usual ctrl key).

from http://ubuntuforums.org/showthread.php?t=1293081

  • 9
    Just a note - this doesn't swap the keys, it just makes the command keys additional control keys. – Fabian Tamp Aug 6 '13 at 4:08
  • This does not work for Ubuntu 16.04. – Unique Feb 26 '18 at 11:32
  • This seems to lead to the desired behavior in Ubuntu 18.04 – RM de Vos May 22 '18 at 20:18

Go to system settings and then to keyboard layout, then to options, then to Win/Alt key behavior, and then check the "Meta switches Ctrl" and then in the Ctrl Position check "Ctrl switches Meta" and there you have it!

on 12.04.1 you change this by:

First, going to "System Settings" then clicking on "Keyboard" then "Layout Settings" (in the bottom left), then "Options" in the bottom right, then expanding the "Alt/Win key behavior" tab, then selecting "Control is mapped to win Keys (and the usual Ctrl keys)"

  • Worked for me in 12.04. I can't actually believe it, but it worked. After hours of messing with .xmodmap – jyoseph Jan 4 '13 at 22:55
  • This is great, thanks. I have the newer system (what you describe in the second paragraph). Ctrl is mapped to Win keys makes Cmd behave as Ctrl. Ctrl key position -> Left Ctrl as Meta does the opposite. Also as a side note, I had to go to Startup and Shutdown -> Service Manager -> Startup Services and activate Keyboard Daemon (this was off by default). – 0__ Feb 20 '14 at 14:16
  • 14.04 doesn't seem to have that "Options" link. – Waldir Leoncio Apr 14 '15 at 11:22
  • As for Ubuntu 15.04, this option is available now at "Input Devices>Keyboard>Advanced tab>Alt/Win key behaviour section>Ctrl is mapped to win Keys (and the usual Ctrl keys)" – Serj Zaharchenko Apr 8 '16 at 9:18
  • 2
    Cant find any of that on Ubuntu 16.04 – Houman Apr 30 '16 at 18:45

The community Ubuntu help page for Apple keyboards gives the following steps to permanently make this change: (tested 2017-05-27)

Run the following command to append the configuration line to the file /etc/modprobe.d/hid_apple.conf creating it if necessary:

echo options hid_apple swap_opt_cmd=1 | sudo tee -a /etc/modprobe.d/hid_apple.conf

Trigger copying the configuration into the initramfs bootfile.

sudo update-initramfs -u -k all

Optionally, reboot

sudo reboot

To temporarily test it out, you can run

echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_opt_cmd

Updated for 18.04 since none of the provided answers seemed to work on my system. I did a clean install of 18.04 and attempting to use a wired aluminum apple keyboard. Default behavior of Left Super on English US is mapped to Gnome Desktop Dashboard. Tweak tool had all the necessary settings in an easy to use GUI!

sudo apt install gnome-tweak-tool

First I swapped the dashboard hotkey to the right side and then under "Additional Layout Options" you can use "Ctrl position/ Swap Left Win with Left Ctrl" to good effect.

  • gnome-tweak-tool is amazing, thank you! – Dennis Golomazov Dec 20 '18 at 19:58
  • This should be the accepted answer. For the Mac, I'm presently finding that Gnome Tweak Tools has the setting I want under Keybord & Mouse > Additional Layout Options > Ctrl position > Swap Left Win with Left Ctrl. The Mac keyboard's Command key seems to be referred to as "Win". – bhaller Jul 7 at 16:56
  • In 2019, in Gnome, this is the easiest solution. Thanks – jymbob Aug 16 at 8:41

Duplicate of How to swap Command and Control keys with xkb step by step?

In 16.04, here's the way I finally got this to work. Xmodmap doesn't work universally in all apps, gnome tweak tool lacked the function, dconf editing a custom altwin2 key swap (like the main answer here) failed, so I was tearing my hair out until I combined several answers into this complete, simple, and elegant solution:

gksudo gedit /usr/share/X11/xkb/symbols/pc

change it to:

default  partial alphanumeric_keys modifier_keys
xkb_symbols "pc105" {

key <ESC>  {    [ Escape        ]   };

// The extra key on many European keyboards:
key <LSGT> {    [ less, greater, bar, brokenbar ] };

// The following keys are common to all layouts.
key <BKSL> {    [ backslash,    bar ]   };
key <SPCE> {    [    space      ]   };

include "srvr_ctrl(fkey2vt)"
include "pc(editing)"
include "keypad(x11)"

key <BKSP> {    [ BackSpace, BackSpace  ]   };

key  <TAB> {    [ Tab,  ISO_Left_Tab    ]   };
key <RTRN> {    [ Return        ]   };

key <CAPS> {    [ Caps_Lock     ]   };
key <NMLK> {    [ Num_Lock      ]   };

key <LFSH> {    [ Shift_L       ]   };
key <LCTL> {    [ Alt_L     ]   };
key <LWIN> {    [ Super_L       ]   };

key <RTSH> {    [ Shift_R       ]   };
key <RCTL> {    [ Alt_R     ]   };
key <RWIN> {    [ Super_R       ]   };
key <MENU> {    [ Menu          ]   };

// Beginning of modifier mappings.
modifier_map Shift  { Shift_L, Shift_R };
modifier_map Lock   { Caps_Lock };
modifier_map Control{ Control_L, Control_R };
modifier_map Mod2   { Num_Lock };
modifier_map Mod4   { Super_L, Super_R };

// Fake keys for virtual<->real modifiers mapping:
key <LVL3> {    [ ISO_Level3_Shift  ]   };
key <MDSW> {    [ Mode_switch       ]   };
modifier_map Mod5   { <LVL3>, <MDSW> };

key <ALT>  {    [ NoSymbol, Control_L, Control_R    ]   };
//include "altwin(meta_alt)"
key <LALT> {    [ Control_L     ]   };
key <RALT> {    [ Control_R     ]   };
modifier_map Mod1   { Alt_L, Alt_R, Meta_L, Meta_R };

key <META> {    [ NoSymbol, Meta_L, Meta_R  ]   };
modifier_map Mod1   { <META> };

key <SUPR> {    [ NoSymbol, Super_L ]   };
modifier_map Mod4   { <SUPR> };

key <HYPR> {    [ NoSymbol, Hyper_L ]   };
modifier_map Mod4   { <HYPR> };
// End of modifier mappings.

key <OUTP> { [ XF86Display ] };
key <KITG> { [ XF86KbdLightOnOff ] };
key <KIDN> { [ XF86KbdBrightnessDown ] };
key <KIUP> { [ XF86KbdBrightnessUp ] };

hidden partial alphanumeric_keys
xkb_symbols "editing" {
key <PRSC> {
type= "PC_ALT_LEVEL2",
symbols[Group1]= [ Print, Sys_Req ]
key <SCLK> {    [  Scroll_Lock      ]   };
key <PAUS> {
symbols[Group1]= [ Pause, Break ]
key  <INS> {    [  Insert       ]   };
key <HOME> {    [  Home         ]   };
key <PGUP> {    [  Prior        ]   };
key <DELE> {    [  Delete       ]   };
key  <END> {    [  End          ]   };
key <PGDN> {    [  Next         ]   };

key   <UP> {    [  Up           ]   };
key <LEFT> {    [  Left         ]   };
key <DOWN> {    [  Down         ]   };
key <RGHT> {    [  Right        ]   };


rm -rf /var/lib/xkb/*

(I don't know if this is required, but I did it.)


  • This was nice but I am unable to use the same trick to switch my ALT keys as a left Control key. It seems ALT keys work differently. Do you know how can I do it? – Pierre Thibault Jan 14 '18 at 15:23
  • The same trick works for anything. You have to switch both the key mappings as well as the modifier_map mappings. You can also jump into gnome tweaks or gconf, i forget which, and there are several toggle settings like "swap ctrl and alt". – Tom Mercer Jan 15 '18 at 2:53
  • We cannot do a: key <LALT> { [ Control_L ] }; key <RALT> { [ Control_L ] }; Alt is treated differently. So I used Gnome Tweaks. I was not able to have what I wanted exactly but it is not so bad. – Pierre Thibault Jan 15 '18 at 6:01
  • I'm not sure I understand your problem. If you just want both alts to behave as controls, the file exactly as above will make both alt keys behave as controls, and both control keys behave as alts. If you can specify what you want each key to be, maybe I can help? Did you try this file? What machine are you using, and which keyboard? French keyboard layout might be giving us trouble. – Tom Mercer Jan 15 '18 at 18:55
  • No, I didn't try the file. I can see that later in the file you are making the switch of two alt to two ctrl. I missed that. Thank you for pointing it. I will try it. – Pierre Thibault Jan 15 '18 at 22:46

You may find Kinto to be useful. It's a project I recently created, after a few years of tackling this problem a few different ways and I just now feel like it's solid enough to share.

The Kinto installer simply uses python to do the initial install, after that it's just a systemd service, bash, xprop, setxkbmap and xkbcomp. As far as I am concerned it is the fastest and most native solution to this problem that you are going to find.



Here's a Gist as well, if you just want to see what is at the heart of it all, it will not alternate your keymap when needed though. The Gist also does not include custom xkb keymap files that setup macOS style cursors/word-wise manipulations that use Cmd and the arrow keys.


gist content

# permanent apple keyboard keyswap
echo "options hid_apple swap_opt_cmd=1" | sudo tee -a /etc/modprobe.d/hid_apple.conf
update-initramfs -u -k all

# Temporary & instant apple keyboard keyswap
echo '1' | sudo tee -a /sys/module/hid_apple/parameters/swap_opt_cmd

# Windows and Mac keyboards - GUI (Physical Alt is Ctrl, Physical Super is Alt, Physical Ctrl is Super)
setxkbmap -option;setxkbmap -option altwin:ctrl_alt_win

# Windows and Mac keyboards - Terminal Apps (Physical Alt is Super, Physical Super is Alt, Physical Ctrl is Ctrl)
setxkbmap -option;setxkbmap -option altwin:swap_alt_win

# If you want a systemd service and bash script to help toggle between
# GUI and Terminal applications then look at project Kinto.
# https://github.com/rbreaves/kinto
# Note: The above may not work for Chromebooks running Linux, please look
# at project Kinto for that.
# If anyone would like to contribute to the project then please do!

protected by Community Sep 21 '18 at 6:56

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.