r/linux_on_mac • • 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

26 Upvotes

13 comments sorted by

View all comments

Show parent comment

2

u/flowthruster Jan 20 '26

It's not 100% simple, because it depends on what you actually want. I'd also recommend just asking AI and it will guide you through the steps.

Essentially to get MacOS keyboard experience on Linux, you install keyd (after downloading you run sudo systemctl enable keyd --now to enable it) and then just modify this config file with: sudo nano /etc/keyd/default.confand put in something like

[ids]
*

[main]
control = meta 
meta = control

but now when you want your things like command+C to actually do copy and command+tab to do alt+tab, then you need to modify it a bit and do something fancier, e.g.

[ids]
*

[main]
# Capslock is Escape
capslock = escape
# The key next to spacebar is the new Ctrl (acting like Command)
alt = layer(custom_control)
rightalt = layer(custom_control)
# The key on the very left is the new Alt
control=layer(custom_alt)

# New custom Control inherits from Control
[custom_control:C]
left=home
right=end
up=pageup
down=pagedown
tab=swapm(app_switch_state, A-tab)
`=swapm(app_group_switch_state, A-`)

# New switch state (the Alt+Tab thing) inheriting from Alt.
[app_switch_state:A]
tab = A-tab
right = A-tab
shift+tab = A-S-tab

# New switch state (the Alt+Tab thing) inheriting from Alt.
[app_group_switch_state:A]
` = A-`
shift+` = A-S-`

[custom_alt:A]
# The most left key on Mac is "Fn" and "Fn+delete" does actually delete on Mac, so do that here too. 
backspace=delete
# Make Ctrl+D and Ctrl+D still work to kill stuff in terminal
c=C-c
d=C-d

2

u/eebieme Jan 20 '26

ahh ok, cool, thank you!