0
0
Azurecloud~5 mins

Azure CLI and Cloud Shell - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to manage your cloud resources quickly without opening a full portal. Azure CLI and Cloud Shell let you type commands to create, update, or check your cloud setup easily from anywhere.
When you want to create a virtual machine without using the web portal.
When you need to check the status of your cloud resources from a remote computer.
When you want to automate tasks like starting or stopping services with scripts.
When you prefer typing commands instead of clicking through menus.
When you want a ready-to-use environment with tools pre-installed for managing Azure.
Commands
This command logs you into your Azure account so you can manage your resources. It opens a browser window to enter your credentials.
Terminal
az login
Expected OutputExpected
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ABCD1234 to authenticate. You have logged in. Now let us find all the subscriptions to which you have access... [{ "cloudName": "AzureCloud", "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "isDefault": true, "name": "My Subscription", "state": "Enabled", "tenantId": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy", "user": { "name": "user@example.com", "type": "user" } }]
This command creates a group to hold your cloud resources in the East US region. Groups help organize and manage resources together.
Terminal
az group create --name myResourceGroup --location eastus
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup", "location": "eastus", "managedBy": null, "name": "myResourceGroup", "properties": { "provisioningState": "Succeeded" }, "tags": {}, "type": "Microsoft.Resources/resourceGroups" }
--name - Sets the name of the resource group
--location - Specifies the Azure region for the group
This command creates a virtual machine named myVM in the myResourceGroup group using the latest Ubuntu image. It also creates SSH keys for secure login.
Terminal
az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --generate-ssh-keys
Expected OutputExpected
{ "fqdns": "", "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM", "location": "eastus", "name": "myVM", "powerState": "VM running", "privateIpAddress": "10.0.0.4", "publicIpAddress": "52.170.12.34", "resourceGroup": "myResourceGroup", "zones": "" }
--resource-group - Specifies the group where the VM will be created
--name - Sets the name of the virtual machine
--image - Chooses the operating system image for the VM
--generate-ssh-keys - Creates SSH keys if none exist for secure access
This command lists all virtual machines with their status in a simple table format so you can see which ones are running.
Terminal
az vm list -d -o table
Expected OutputExpected
Name ResourceGroup Location Zones PowerState ------ --------------- ---------- ------- ------------ myVM myResourceGroup eastus VM running
-d - Shows instance view including power state
-o - Formats output as a readable table
This command logs you out of your Azure account to keep your session secure when you finish working.
Terminal
az logout
Expected OutputExpected
No output (command runs silently)
Key Concept

If you remember nothing else from this pattern, remember: Azure CLI lets you control your cloud resources quickly by typing commands, and Cloud Shell gives you a ready-made place to run these commands anywhere.

Common Mistakes
Trying to run Azure CLI commands without logging in first.
Commands fail because Azure needs to know who you are to allow access.
Always run 'az login' before other commands to authenticate.
Not specifying the resource group when creating resources.
Azure cannot place the resource properly, causing errors or confusion.
Use the --resource-group flag to specify where the resource belongs.
Ignoring the output format and getting hard-to-read JSON by default.
It makes it difficult to quickly understand the status or details.
Use '-o table' or other output flags to get clear, readable results.
Summary
Use 'az login' to sign in to your Azure account before managing resources.
Create and organize resources with commands like 'az group create' and 'az vm create'.
Check resource status with 'az vm list' and log out securely with 'az logout'.