Deploy a Virtual Machine on Azure Using Azure CLI

Table of contents
📌 What You’ll Learn:
How to create a Resource Group.
How to deploy a Virtual Machine using Azure CLI.
How to connect to the VM.
(Optional) How to clean up resources.
✅ Step 1: Prepare Azure CLI
Make sure you have:
Azure CLI installed → Install guide here
An active Azure account → You can use the free tier.
✅ Step 2: Login to Azure
az login
This opens a browser window for you to sign in.
✅ Step 3: Create a Resource Group
az group create --name myharmzyRG --location eastus
Replace
myharmzyRG
with your preferred name.You can also choose other locations like
westeurope
orcentralus
.
✅ Step 4: Create a Virtual Machine
az vm create \
--resource-group myharmzyRG \
--name myVM \
--image Ubuntu2204 \
--admin-username azureuser \
--generate-ssh-keys
myVM
is the VM name.azureuser
is the admin username.--generate-ssh-keys
creates SSH keys for you to connect securely.
✅ Step 5: Open Port 80 to Allow Web Traffic
az vm open-port --port 80 --resource-group myharmzyRG --name myVM
✅ Step 6: Connect to the VM
Get the VM public IP address:
az vm show --name myVM --resource-group myharmzyRG -d --query publicIps -o tsv
Use the IP address to SSH into the VM:
azureuser@<your-public-ip>
when you successfully connect to the VM the Terminal Prompt Changes to:
This:
azureuser@myVM:~$
This shows you’re now “inside” the VM, not on your local Mac.
When you’re done, type:
exit
It will return you to your Mac’s terminal:
✅ Step 7: Clean Up Resources (Optional)
When you’re done, delete everything to save costs:
az group delete --name myharmzyRG --yes --no-wait
🎯 Final Thoughts
What I Learned
How to deploy cloud resources using Azure CLI.
How to connect to a VM using SSH.
Basic cloud resource management (setup and teardown).
Resources
Subscribe to my newsletter
Read articles from Anigbogu Chioma Paschaline directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Anigbogu Chioma Paschaline
Anigbogu Chioma Paschaline
Hi, I’m Anigbogu Paschaline Chioma, an aspiring Cloud Engineer documenting my journey one step at a time. Through CloudSteps, I share beginner-friendly tutorials, personal projects, and insights from my hands-on learning in cloud computing, DevOps, and modern tech tools. Follow along as I learn, build, and grow — one step closer to the cloud.