This guide provides a comprehensive walkthrough for setting up an Azure environment from your Mac. Whether you are prepping for a certification or building a personal lab, these steps will take you from a blank terminal to a running Linux server.
1. Install Azure CLI & Login
On macOS, the most efficient way to manage the Azure CLI is through Homebrew.
Step-by-Step Installation:
-
Open Terminal: Press
Cmd + Space, type "Terminal," and hit Enter. - Update Homebrew: Ensure your package manager is current.
brew update
- Install Azure CLI:
brew install azure-cli
- Login to Azure: Run the following command. It will automatically open your default web browser (Safari/Chrome).
az login
-
Pro Tip: If your browser doesn't open or you are on a remote server, use
az login --use-device-code.
- Set your Subscription: If you have multiple accounts, list them and select the correct one:
az account list --output table
az account set --subscription "Your-Subscription-Name"
2. Create a Resource Group
A Resource Group (RG) is a logical container. Deleting the RG later will automatically clean up all resources inside it, preventing "ghost" charges on your bill.
Run this command:
az group create --name MyLabGroup --location eastus
- --name: The identifier for your group.
-
--location: Choose a region close to you (e.g.,
eastus,westeurope,southeastasia).
3. Build a Virtual Network (VNet) & Subnet
Before you can drop a VM into Azure, you need a network. We will create a VNet and a Subnet simultaneously.
Run this command:
az network vnet create \
--resource-group MyLabGroup \
--name MyVNet \
--address-prefix 10.0.0.0/16 \
--subnet-name MySubnet \
--subnet-prefix 10.0.1.0/24
- 10.0.0.0/16: This is your private "building."
- 10.0.1.0/24: This is a specific "room" (subnet) within that building where your VM will live.
4. Provision a Linux Virtual Machine
Now, let's launch an Ubuntu 22.04 VM. This command handles the compute, creates a Public IP, and secures it with SSH keys.
az vm create \
--resource-group MyLabGroup \
--name MyLinuxVM \
--image Ubuntu2204 \
--vnet-name MyVNet \
--subnet MySubnet \
--admin-username azureuser \
--generate-ssh-keys \
--public-ip-sku Standard
What's happening here?
-
--generate-ssh-keys: This is the "Magic Mac" flag. It looks in your
~/.sshfolder for a key; if it doesn't find one, it creates one for you automatically. - --public-ip-sku Standard: Assigns a static-capable IP so you can reach the machine from your laptop.
5. Verify & Connect
Once the command finishes, you will see a JSON output. Look for the publicIpAddress field.
To connect from your Mac:
ssh azureuser@<YOUR_PUBLIC_IP>
If this is your first time connecting, type yes when asked about the authenticity of the host.
Summary of Commands
| Action | Command Snippet |
|---|---|
| Install | brew install azure-cli |
| Login | az login |
| Create Group | az group create -n <name> -l <location> |
| Create Network | az network vnet create ... |
| Create VM | az vm create ... |
Would you like me to provide a script to automatically shut down or delete these resources so you don't get charged when you're finished with your lab?
Top comments (0)