Installing Debian Linux on Mac OS

This is a guide to installing Debian on Mac OS as a virtual machine. These instructions assume you will be using it headless (meaning you will only interact with it through ssh and not through a GUI. In essence, you will treat it as a remote server that happens to be running on your local machine.

Here is a screencast that walks through this process. I recommend watching it and following along, using these written instructions as a reference:

Download the Debian installer

Start at the Debian website:

From there, find the right installation image:

This will download the .iso file, typically to your “Downloads” directory (make note of where you save it).

Install UTM

UTM is a free virtual machine system for Mac OS based on the qemu project. Download it from the main website:

Click on the “Download” link and install it as you would a normal Mac OS app.

Install Debian

Launch UTM and follow these steps:

Tell UTM to install from your Debian install image

Choose the hardware resources to give to the VM

Run the installer

The installer will start by configuring the network. Make sure you have a solid internet connection as it will download most packages directly from the internet to make sure you have the latest versions. This saves you having to upgrade everything right after installing.

Since this VM will only ever run on your machine and is not accessible to the rest of the world, we can use simple defaults and lax security.

Next it will ask you to partition the disk:

The next section asks you to choose a Debian mirror that it will use to download and install packages

On the software selection page you will tell it what basic packages to install:

Reboot the VM into the newly-installed system

When the installation is complete, you must eject the install media (UTM is emulating an installion DVD) so that when you reboot it will start the new system and not re-run the installer.

At the GRUB menu you will see “Debian GNU/Linux” as the default option. Either hit enter to continue or let it sit for 5 seconds or so and it will continue automatically.

Configure the system directly through the VM window

There are a few setup steps you will complete directly in the VM window. The VM window is inconvenient because Mac OS essentially sees it as a video window and does not know how to interact with it, so things like copy-and-paste do not always work well.

root is the administrative user and you will rarely use it in practice, but you will use it now to complete enough setup that the main user can take over.

Run this command:

apt install sudo

Next run:

usermod -aG sudo student

If you named your used account something other than “student” you should modify that command to use the appropriate account name.

Now you need to get the IP address of the VM. Type:

hostname -I

and take note of the IP address at the beginning of the output line. It will probably be something like “192.168.64.3” but yours may vary.

Now you can log out as root by typing “exit” or hitting ctrl-d

You are finished interactive directly with the VM window, so you can minimize it to get it out of the way.

Connect to the VM through the terminal

Next launch the Mac OS terminal app and use it to connect to the VM using this command:

ssh student@192.168.64.3

but you should substitute in the account name you created and the IP address you noted earlier.

You are now connected to the VM through an ssh connection, similar to how you would normally interact with a server. You can hit ctrl-d to exit back to the Mac OS shell. Note that there are two distinct shells:

Set up ssh for easier connections

Every time you want to use the VM, you will need to make sure it is running (you may need to launch UTM if it is not already running and boot the VM if it is not already started) and then connect to it via ssh. To make that last part simpler we will complete a few additional steps.

Launch a Mac OS terminal and do NOT connect to the VM. Check if you have an ssh keypair already by typing:

cd
ls .ssh

If you see a file called id_rsa then you already have a key and should skip the next step. If you do not see it, or if ls .ssh gives you an error, then you should generate a new keypair by typing:

ssh-keygen

Hit enter to accept the default location for saving it, again to set an empty passphrase, and again to confirm. Now repeat this part:

ls .ssh

You should see files called id_rsa and id_rsa.pub.

Now type:

ssh-copy-id student@192.168.64.3

Substituting your account name and IP address as before. You will need to enter the password again as well.

This tells the VM to trust your account so that you can login without a password in the future (it will confirm your identity using the ssh keys instaed).

Try running the ssh command to login again:

ssh student@192.168.64.3

(substitute your username and IP address as before). It should login without requiring a password.

Hit ctrl-d to get back to Mac OS.

Edit a new file called .ssh/config using vim or your editor of choice. For example:

vim ~/.ssh/config

or

nano ~/.ssh/config

If you have not used vim before, then you will probably have better luck with nano.

In that file, add the following:

Host cs2810
    User student
    HostName 192.168.64.3

(substitute your account name and IP address)

After you save it, you should be able to connect to the VM using just:

ssh cs2810

No password, no username, and no IP address required.

In the future, you can launch the VM, then launch a terminal window and type that one command to connect. If you use vscode, you can also give it that command when using the remote development plugin and it can connect to the VM using your ssh configuration.

Next steps

From here you should go to the “Setting up Linux for CodeGrinder assignments” link on the CS 2810 page and follow the instructions. From this point forward they are the same for Windows with WSL and Mac OS with a VM.