Imagine this: your boss needs a new web server spun up right now—and you’re the go-to person. You could click around in the Azure portal, but let’s be honest, that’s slow and error-prone. Real pros use the az CLI to automate, control, and dominate their Azure VMs. If you want to move fast and avoid mistakes, this guide is for you.
Step 1: Create a Resource Group
Resource groups are the containers for your Azure resources. Always start here—don’t be the person who dumps everything into the default group.
az group create --name someRG --location eastus
- Tip: Pick a location close to your users for lower latency.
- Gotcha: Resource group names must be unique within your subscription.
Step 2: Create a Linux VM
Now, let’s launch a VM. Ubuntu LTS is a solid, secure choice for most workloads.
az vm create --resource-group someRG --name someVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys
- Tip: Use
--generate-ssh-keysto avoid password headaches. - Gotcha: Don’t forget
--admin-username—the default is not always what you expect.
Step 3: VM Lifecycle Management
VMs aren’t fire-and-forget. You’ll need to redeploy, start, stop, and inspect them. Here’s how:
az vm redeploy --resource-group someRG --name someVM
az vm start --resource-group someRG --name someVM
az vm deallocate --resource-group someRG --name someVM
az vm show --resource-group someRG --name someVM
- Tip:
deallocatestops billing for compute—don’t pay for idle VMs! - Gotcha: Redeploy is your secret weapon for fixing weird networking issues.
Step 4: Get the Public IP Address
Need to connect? Grab your VM’s public IP like a pro:
az vm show -d -g someRG -n someVM --query publicIps -o tsv
- Tip: The
-dflag gives you instance details, including IPs. - Gotcha: If you don’t see an IP, check your network settings—public IPs aren’t enabled by default on all VM images.
Step 5: Remote Command Execution
SSH in and run commands. Here’s how to check your VM’s uptime:
ssh azureuser@<VM_PUBLIC_IP> 'uptime'
- Tip: Replace
<VM_PUBLIC_IP>with the actual IP from the previous step. - Gotcha: Make sure your local SSH key matches the one on the VM, or you’ll get locked out.
Final Thoughts
The az CLI is your ticket to fast, repeatable, and reliable VM management. Don’t settle for point-and-click—automate everything, and keep your cloud under control. If you hit a snag, check the official docs or run az vm --help for more options.
Leave a Reply