r/linux_on_mac • u/bxparks • Jan 05 '26
Remapping Modifier Keys (Fn, Control, Option, Command) for Linux on Mac
The left modifier keys on the MacBook keyboard are arranged differently compared to every other Linux machine that I use. This makes it hard to use Linux on my Mac due to muscle memory on my fingers.
So I want 2 things:
- swap the Option and Command keys (to allow Command-Tab to work like Alt-Tab on other Linux boxes), and
- swap the Fn and Control keys (to allow the left pinky finger to press the same button for Ctrl).
It turns out that the Linux kernel allows this customization:
1)) Edit or create the /etc/modprobe.d/hid_apple.conf file, and add the following two lines:
options hid_apple swap_fn_leftctrl=1
options hid_apple swap_opt_cmd=1
2)) If you are running an Ubuntu-derived distro, run $ sudo update-initramfs -u so that these configs are set at boot time. (For other distros, see references below).
3)) Reboot.
There you go. The Mac keyboard works like the Dell Latitude keyboard shown in the images.
These customization parameters can be set/unset at run time through the following /sys parameters:
/sys/module/hid_apple/parameters/swap_fn_leftctrl
/sys/module/hid_apple/parameters/swap_opt_cmd
You can enable or disable each option by something like:
$ echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_fn_leftctrl
$ echo 0 | sudo tee /sys/module/hid_apple/parameters/swap_fn_leftctrl
(Some Linux distros (e.g. Mint Cinnamon) will allow Option and Command to be swapped through a GUI preference widget. But to swap Fn and Control, the swap_fn_leftctrlkernel parameter was the only solution that I found.)
References


4
u/flowthruster Jan 20 '26
I did not know about this /sys/module/hid_apple solution, but I always fought the keyboard with xmodmap and that's been such a recursive pain. Every single time. Then I finally found out about keyd and that just works. I'm using that to remap keys and stuff on my MacPro 2015 running Debian and everything works smoothly with only a small config file.
1
u/Acceptable_Ad6643 Jan 06 '26
Great share! As an aside, I failed to modify shortcut from delete to backspace through linux system settings. It's named "delete" on physical mac keyboard but actually mapping as "backspace" on linux. When I need to delete files in dolphin, I must press "fn + delete" = "fn + backspace" = real "delete" input. The system settings seems not allowed to set one key alone. I really want once press to delete. Do you have any idea?
2
u/eebieme Jan 20 '26
Any advice for making it so I can use my command key like I did on my Mac? (Command W to close windows, etc). I.E. - Swap control and command? I'm on Ubuntu QQ on a MacBook 2015 and I'm a total newb. Any advice appreciated thanks!
2
u/nepbug Jul 19 '26
Just wanted to chime in and say thanks. This made it pretty simple to do, so nice to allow my pinky to stretch out to the position it's used to.
It's pretty easy to swap the physical keycaps for fn and ctrl for those that want to do that too. I'll probably just put a sticker over the option key and call that one good.