How to setup CMD key for Ubuntu running in VirtualBox on MacOS

How to setup CMD key for Ubuntu running in VirtualBox on MacOS

How to swap Control for Host (Command, CMD) key in VirtualBox (Ubuntu) on MacOS (Macbook)

When you start working on Ubuntu VM [running on MacOS in VirtualBox], you will discover that the CMD (⌘) key does not work the same way it did on your Macbook. On MacOS you must do CMD+C to copy something. On Ubuntu you must instead do CTRL+C to copy something. Definitely not what you want! If you press CMD+C when inside the Ubuntu VM, you will instead break out of VirtualBox’s Full Screen mode.

READ  How to set resolution, Ubuntu Guest OS running in VirtualBox on MacOS

Follow the screenshots to use CMD+C to copy something when inside the Ubuntu VM. There are two separate areas you need to change.

  1. On the VirtualBox application, you must change the host key’s keyboard mapping. I’m using VirtualBox 6.0 for this example.
  2. Inside Ubuntu, you must add 2 lines of code.

1. Open VirtualBox and click on Tools

If tools is absent, got to VirtualBox and download the extension pack for all platforms.


2. Click on Preferences


3. Click on Input


4. Click on Virtual Machine.

The default selection is VirtualBox Manager. Go to Virtual Machine options instead.


5. You will find the Host Key Combination set to Left ⌘

We need to change this to Right ⌘


6. Click on the shortcut


7. Press the Right ⌘ key

(or any other key that you rarely use)


8. Confirm the change in shortcut value

The shortcut value will automatically change to Right ⌘. You cannot type anything there.


9. Save your changes

Press OK to save your changes.


The remaining changes are in your VM.


10. Open your VM

Double click to launch the VM


11. Time for some code.

Create a file called ctrl2cmd.sh with the following code:

xmodmap -e "remove mod4 = Super_L"

xmodmap -e "add control = Super_L"

echo "mapped control to command"


12. Ensure that this file is executable

Prompt> chmod 755 ~/ctrl2cmd.sh


13. Add a line to the end of your bash profile file

Prompt> vi ~/.bashrc

Add the ~/ctr2cmd.sh to the end of this file and save it. This will preserve these changes across system restarts.


14. Log out and Log back in.

You can use now use CMD+C to copy when inside your Ubuntu VM 🙂

Note: If you don’t want to log out, re-source the bash profile instead.

Prompt> source ~/.bashrc


Please leave a comment and let us know how it went.

Thank You!


Advertisements

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Terms of Use | Privacy Policy 
2018-2019 © eXitDiscount