Post

How I Set Up Visual Studio Code Remote with Multipass on macOS

A post about how I set up Visual Studio Code Remote with Multipass on macOS to get a WSL-like experience.

How I Set Up Visual Studio Code Remote with Multipass on macOS

Visual Studio Code Remote Development Extension is an excellent idea with easy-to-use user experience. You can easily configure if your target machine is an SSH enabled Linux machine, either physical or virtual, in the cloud or on premise.

It works pretty good on Windows 10, as WSL delivers solid Linux experience.

With that in mind, it is natural that you want something similar on macOS, but installing VirtualBox/Parallel can be painful. Well, painful till the Ubuntu guys invented Multipass.

I tried it out today, and really enjoy the simple experience to get things done in just a few minutes.

Set Up Multipass

I always use homebrew, so it takes only a command to install Multipass,

1
brew cask install multipass

Once installed, it gives me a default Ubuntu machine instance that I can shell in from the menu bar,

img-description Figure 1: Multipass menu.

and the shell looks like this,

img-description Figure 2: Multipass shell to an instance.

Set Up Visual Studio Code Remote on macOS

All steps below are performed on macOS.

If you don’t have much Linux/macOS experience, then you definitely find it hard here. So we summarize what Multipass has created for us so far,

  • An Ubuntu virtual machine running on 192.168.64.5.
  • A default user named ubuntu.
  • (This is hidden from you) A private key to log in at /var/root/Library/Application\ Support/multipassd/ssh-keys/id_rsa.

Therefore, to make it easy to configure in VS Code on macOS, I simply copy that private key to my own macOS account,

1
sudo cp /var/root/Library/Application\ Support/multipassd/ssh-keys/id_rsa ~/.ssh/

Make sure you don’t have ~/.ssh/id_rsa.pub there, because that can lead to conflicts.

Launch a terminal to test out the connection,

If succeeded, then time to move on to VS Code (with Remote Development Extension installed).

  1. Choose View | Command Palettes … menu item.
  2. Choose Remote-SSH: Connect to Host… from the palette.
  3. Choose + Add New SSH Host… from the drop down list.
  4. Enter ssh [email protected].
  5. Select /Users/lextm/.ssh/config as lextm is my macOS account.

VS Code informs that the host is added,

img-description Figure 3: SSH host added.

You can click Connect now to open SSH connection, or click Open Config if you want to change the host setting (such as its name).

At this moment, your adventure on VS Code/Multipass can start.

© Lex Li. All rights reserved. The code included is licensed under CC BY 4.0 unless otherwise noted.
Advertisement