macOS to Linux & Back Again

Ben Reaves
3 min readJul 15, 2021

--

So I am the author of kinto.sh and one of the things that I have ensured users of my app is the ability to remotely access Linux or Windows with their macOS based keybinds intact — but what about going back to macOS from Linux or Windows while using a non-Apple keyboard?

Until recently I had not tried this and for a few reasons, the built-in screen-sharing of macOS via VNC has always been a subpar experience for me compared to something as sophisticated as RDP. Of course if you want to purchase a license for iRAPP, or what is now Nuords RDP server, for macOS then you can have much better performance at a cost of about $50 a year. That’s an ok deal — but lately I have found a cross-platform application that is free for personal use and has identical, if not better performance even, NoMachine.

Ok, so that quickly gets to how, or what to use rather, to remote into macOS or Linux even (combine xRDP w/ NoMachine and it becomes even more flexible for screen sizes that can literally change and scale perfectly on a whim). What about the key mapping though? If your keyboard is not already laid out like that of a macbook then you may be in for a bit of a surprise when your keys no longer line up properly for macOS. Every remote desktop application I came across also seemed to lack the ability to remap your keys as well, commercial or not. Also the very simple modifier key remap built-in to macOS is completely useless during remote desktop use or VNC solutions, even the one built-in.

For Windows the solution is likely pretty simple — you can likely use Autohotkey or modify kinto.sh to remap your keys during a specific remote application having focus. If that fails to work then Sharpkeys can remap your keys for sure & if you want to continue to use Kinto locally then you can change its keyboard type to Apple for proper keymaps during normal usage.

Lastly and what this article is really written for is how you can accomplish remote desktop use for macOS from Linux. This was rather difficult and I almost gave up on figuring it out because every other method I was aware of kept failing, xmodmap, uinput via xkeysnail, setxkbmap options, & hwdb, but finally I found setkeycodes and the series of steps one would need to perform. I may try and automate this later, but for now mentioning it here will have to do.

Linux Remap for macOS Remote Access

sudo setkeycodes {scancodes} {keycodes}# Your scancodes are the literally address of your physical keys.
# Your keycodes are the letters those physical keys trigger when pressed.
# May need to install evtest.# Discover Scancodes (hexadecimal) for Ctrl, Win/Super, Alt
sudo showkey --scancodes
# Discover Keycodes (decimal) for Ctrl, Win/Super, Alt
sudo showkey --keycodes
# The following will be unique to your laptop or desktop, so do not use mine, unless you happen to have the same Chromebook I have.# Note: This example only shows what my values were on the left side of the keyboard, this procedure can easily be repeated for the right side keys as well if you wish to do so.# Physical scancodes
Ctrl: 1d
Win/Super: e05b
Alt: 38
# Letter's keycodes
Ctrl: 29
Win/Super: 125
Alt: 56
# Set your Laptop, desktop or Chromebook to use the Apple Layout
sudo setkeycodes 1d 56
sudo setkeycodes e05b 29
sudo setkeycodes 38 125
# Set your values back to their original values
sudo setkeycodes 1d 29
sudo setkeycodes e05b 125
sudo setkeycodes 38 56

Additional information on setkeycodes (near the bottom) can also be found here. https://wiki.archlinux.org/title/Map_scancodes_to_keycodes

--

--