Skip to main content

⚡ Fast & Light Linux VM + GUI on MacOS

·7 mins

Fed up with clunky Multipass, UTM, or VirtualBox setups for school/work?

Let’s get set up in minutes with a much better alternative!

  • Works on  Macs with Apple Silicon (M-series) or Intel chips
    • emulate both arm and x86 arch
  • copy/paste between Mac and VM
  • setup in <5m, instant bootup
Looking for a setup guide to a UCSC Class? Skip to here

Prerequisites #

Very simple, caveman clicks button and installs:

Create VM #

Default settings are fine

ubuntu

Connect to VM #

Default #

If you only have 1 VM, double-click it in OrbStack or ssh orb from a terminal

Multiple #

If you have multiple, for the default just do like done above, but for another do:

ssh <vmname>@orb

or just double-click in OrbStack

GUI #

Installation #

Inside the VM, run this:

sudo apt install -y openssh-server xauth x11-apps nscd

What is this doing?

  • openssh-server: Enables remote SSH access
  • xauth: Manages X11 forwarding auth
  • x11-apps: Provides basic X11 GUI tools
  • nscd: Grants browsers access to the internet

Setup #

Still in the VM, run this:

sudo vim /etc/ssh/sshd_config

This brings up config, find and ensure these lines are set like this:

helpful: i to edit, :wq to save + exit, :q! to force quit without save if you mess up

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes

Now saved, let’s reload:

sudo systemctl restart ssh

Let’s set a password (anything is fine, just remember it):

sudo passwd $USER

Let’s also allow browsers to use the GUI:

echo 'export XAUTHORITY=$HOME/.Xauthority' >> $HOME/.profile

Connect (w/GUI) #

Important: Do this inside a fresh new MacOS terminal (not VM)

Connect with X11 (-X) forwarding:

ssh -X vmnname.orb.local

Replace vmname with the name of your VM, e.g. mininet

App Usage #

Now that you’re ssh -X’d into the VM, you can run GUI apps!

Run apps (in background):

app &

Replace app with the app you want to run, e.g. wireshark, firefox, code, etc.

Also note, bidirectional clipboard is supported!

  • Command + C to copy on MacOS
  • Ctrl + V to paste on GUI
  • and vice versa

Code in VSCode #

Here’s how to edit in VSCode if you’re a Vim hater

  1. Install Remote - SSH
  2. Open VSCode, click TV icon on left sidebar or left-most-bottom icon

Default #

If you only have 1 VM, it should already show up as orb, just click it and you’re in

Multiple #

If you have multiple, for the default just connect to orb, but for another do:

  1. Connect to Host
  2. Add New SSH Host
  3. ssh vmname@orb
  4. Cmd + Shift + P, type in “Install code PATH” and enter
  5. Now just open up a fresh terminal
  6. Do as you please, use code <filepath> to open stuff in VSCode

with GUI #

Now sometimes, you want to avoid having a seperate terminal, and separate VSCode

  • Why?
    • The seperate terminal is where you ssh -X ...
      • this means GUI enabled
    • VSCode’s connection is just a regular ssh ...

First, install the Remote X11 extension

Then do the steps above, but replace #3 with ssh -X vmname.orb.local

Only caveat is you have to input your password every time you open VSCode (you’ll live)

UCSC Classes Setup #

Many programming classes require a Linux VM, let’s get set up!

Skip to the class you want:

SSH Setup #

Let’s link up your VM to your git.ucsc.edu or GitHub account

Generate a new SSH key:

ssh-keygen -t rsa -b 4096 -C "OrbStack" -N ""

Add the key to your SSH agent:

eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa

Now let’s grab the public key:

cat ~/.ssh/id_rsa.pub

Now add the output of this to:

  • Preferences > SSH Keys > Add new key if on git.ucsc.edu
  • Settings > SSH and GPG Keys > New SSH key (or login and click this) if on GitHub

You can name the key whatever, I just go with OrbStack

CSE 13S, 101, 130 #

Open this guide on a laptop, so you can jump back here through the right sidebar

For C/C++ based classes

  1. Do prereqs (GUI not needed), create the VM like done here, then come back here

  2. Simply ssh orb, then run the following:

sudo apt install clang clang-format clang-tools make net-tools valgrind
  1. Setup SSH to hook up to your class repo(s) like done here

  2. Setup to code through VSCode like done here

Some VSCode extensions to make your life easier:

  • C/C++ Extension Pack Syntax highlighting
  • Error Lens See errors without hovering
  • Clang-Format Auto-formatting
    • Cmd + Shift + P and type in “Format Document With
    • Configure Default Formatter > Set to clang-format
    • Go to editor settings, search for and enable “Format on Save

CSE 30, 40, 140/X, 183 #

Open this guide on a laptop, so you can jump back here through the right sidebar

  1. Do prereqs (GUI not needed), create the VM like done here, then come back here

  2. Simply ssh orb, then run the following:

sudo apt install python3-dev python3-venv python3-pip python-is-python3
  1. Setup SSH to hook up to your class repo(s) like done here

  2. Setup to code through VSCode like done here

Some VSCode extensions to make your life easier:

  • Python Extension Pack Syntax highlighting
  • Python Auto Venv Auto-activate venvs
  • Jupyter Support for.ipynb notebooks
  • Black Formatter Auto-formatting
    • Cmd + Shift + P and type in “Format Document With
    • Configure Default Formatter > Set to black
    • Go to editor settings, search for and enable “Format on Save

FAQ #

  1. Sometimes .ipynb / notebooks don’t load, do this:
pip install ipykernel --break-system-packages # don't worry lol
  1. Here’s how to set up a virtual environment (venv) for your class:

For starters, cd into your project dir and create a venv:

python -m venv venv # the second 'venv' is the name, can be anything

Now activate it:

source venv/bin/activate

Now you can install packages:

pip install <package>
# or
pip install -r requirements.txt

CSE 150 #

Open this guide on a laptop, so you can jump back here through the right sidebar

  1. Do prereqs (GUI needed), then come back here

  2. Since manual config sucks, here’s a faster way with a cloud-init script:

Setup Script
  • Click Raw and then Command + S
  • Save as cloud-init.yml under ~/Desktop (make sure to add the .yml)
  1. Once done, open up a terminal and run:
cd ~/Desktop
orb create -a amd64 -c cloud-init.yml ubuntu:focal mininet

What’s happening here?

  • orb create: Creates a new instance
  • -a amd64: Specifies the architecture: arm64 (ARM) or amd64 (x86)
    • Why not latest? The labs used x86
  • -c cloud-init.yml: Specifies the cloud-init file to use
  • ubuntu:focal: Specifies the Ubuntu version (focal for 20.04)
    • Why not latest? The labs used 20.04 (as of W25)
  • mininet: Specifies the name of the instance

It’ll take <5m to install + config

  1. Still need to do a little bit of manual config, SSH into it:
ssh mininet@orb
  1. We need to change the password to ssh -X into it later:
sudo passwd $USER # set as whatever, just remember it
  1. Nearing the end, just need to install wireshark:
sudo apt install -y wireshark

Select yes on purple screen prompt with key + return key (enter)

  1. Almost done, just need to clone the POX controller:
git clone https://github.com/noxrepo/pox.git
chmod +x ~/pox/pox.py
  1. Done! First type in exit, and then connect using the instructions here
  2. Also, read entirely through App Usage

FAQ #

  • Note that instead of chromium, this script uses firefox for the browser

    • doesn’t make a difference, it’s just faster
  • For OpenFlow labs, use this filter in Wireshark:

openflow_v1

If that doesn’t work, try all nums up till _v6

  • Sometimes your controller might be already binded, let’s kill the existing process:
sudo kill $(sudo lsof -t -i:6653) 2>/dev/null || true