Table of Contents

Azure Cloud Shell is a fully managed service that enables users to interact with Azure resources using a browser-based shell. This innovative service eliminates the need for local installations and configurations of CLI tools, offering a ready-to-use environment accessible from anywhere, at any time. Whether you’re executing simple queries or deploying complex infrastructure, Azure Cloud Shell provides a consistent and integrated experience that complements the Azure Portal.

Our cheat sheet is designed to serve both newcomers and seasoned professionals who seek to leverage the Cloud Shell for efficient cloud management. From basic navigation commands to advanced operational tasks, this guide covers essential CLI commands that are crucial for day-to-day management of Azure services.


What is Azure Cloud Shell?

Cloud Shell is a browser-based, interactive shell that enables users to effortlessly manage Azure resources. It uniquely blends flexibility and efficiency by offering users the choice between Bash and PowerShell interfaces, catering to diverse scripting and operational needs.

It is designed to facilitate the management and configuration of Azure services through a command-line interface (CLI), directly from the browser. This eliminates the cumbersome necessity for local CLI tool installations, offering a seamless and direct pathway to Azure’s vast cloud ecosystem.

Azure Cloud Shell Diagram, Commands, Cheat Sheet

How Does Azure Cloud Shell Work?

Cloud Shell simplifies the command-line experience by provisioning a temporary, browser-accessible host upon session initiation. It pairs ephemeral sessions with persistent storage, ensuring users’ scripts and settings are preserved across sessions through an Azure file share. This setup streamlines the initial setup, providing a ready-to-use environment right from the start.

Deeply integrated with Azure, Cloud Shell comes pre-configured with Azure CLI and PowerShell module support, making cloud resource management seamless and straightforward. It’s more than a command-line tool; it’s a comprehensive environment equipped with popular tools and languages for deployment and management tasks, including built-in Git support for version control.


Tools Available in Azure Cloud Shell

Azure Cloud Shell is pre-loaded with a wide array of tools to support Azure management and general development tasks. These tools include:

  • Linux Tools: Key Linux utilities such as bash, sh, zsh, tmux, and dig are available, offering a familiar command-line environment for Linux users.
  • Azure Tools: A robust set of Azure management tools including Azure CLI, AzCopy, Azure Functions CLI, blobxfer, Service Fabric CLI, Azure Classic CLI, and Batch Shipyard are present, making it easier to manage Azure resources.
  • Text Editors: Cloud Shell includes various text editors like code (Visual Studio Code’s Monaco Editor), nano, vim, and emacs, allowing users to edit files directly within the browser.
  • Container Management Tools: For container orchestration and management, Docker Machine, kubectl, Azure Kubernetes Services, Helm, and DC/OS CLI are included, catering to a wide range of containerized application development and deployment needs.
  • Database Tools: Database clients for MySQL, SQL Server (sqlcmd Utility), PostgreSQL, and mssql-scripter are available, facilitating database management and scripting directly from Cloud Shell.

The combination of these features and tools makes Azure Cloud Shell a powerful, versatile environment for managing Azure resources.


Getting Started with Azure Cloud Shell

Here’s a step-by-step guide to get you started with Azure Cloud Shell:

Access Azure Cloud Shell: You can access Azure Cloud Shell by navigating to the Azure Portal (portal.azure.com) and clicking on the Cloud Shell icon in the top menu, or directly via shell.azure.com. Azure Cloud Shell can also be accessed through the Azure mobile app or the Visual Studio Code Azure Account extension. You will have to choose your billing account type if not done yet.

Choose Your Shell Experience: Upon your first login, Azure Cloud Shell prompts you to choose between Bash and PowerShell. Your choice will determine the command-line interface you’ll be working with. This selection can be changed later if needed.

Set Up Storage: Azure Cloud Shell requires an Azure file share to store scripts, configuration files, and other persistent data. If you’re using Cloud Shell for the first time, you’ll be guided through creating a new storage account tier for this purpose. Existing users can attach to their storage accounts directly.

Start Using Azure CLI or PowerShell: With your environment set up, you can begin using Azure CLI commands (if you chose Bash) or PowerShell cmdlets (if you chose PowerShell) to manage your Azure resources. Cloud Shell comes pre-loaded with the necessary tools and extensions for Azure management.


Azure Cloud Shell Commands + Cheat Sheet

Azure Cloud Shell is a powerful tool, and knowing the right commands can significantly enhance your productivity. Below is a cheat sheet of essential Azure Cloud Shell commands to help you navigate and manage your Azure resources effectively:

Manage and View Azure Resources

Here is a table with basic command line utilities to manage Azure resources.

CommandDescription
az account listLists all the Azure subscriptions accessible by your account.
az group listDisplays all resource groups in your Azure subscription.
az vm createCreates a new virtual machine. Requires specifications such as name, image, and resource group.
az appservice plan createCreates a new app service plan, necessary for hosting web apps and functions.
az storage account listLists all storage accounts under your Azure subscription.
az network vnet createCreates a new virtual network, specifying a name and resource group.
az ad user listLists all users in your Azure Active Directory.
az role assignment listShows all role assignments, helping you manage access controls.
kubectl get podsLists all pods in the current Kubernetes namespace (requires kubectl in Cloud Shell).
helm listDisplays all Helm charts deployed in the Kubernetes cluster (requires Helm in Cloud Shell).

Create VMs in Azure Cloud Shell (CLI)

Below is a table detailing the commands to create virtual machines (VMs) in Azure using the Azure CLI, tailored specifically for both Linux and Windows environments:

TaskAzure CLI Commands
Create a resource groupaz group create --name myResourceGroup --location eastus
Create a Linux VMaz vm create --resource-group myResourceGroup --name myVM --image LinuxImageName
Create a Windows VMaz vm create --resource-group myResourceGroup --name myVM --image win2016datacenter

Following this, you can create either a Linux or Windows VM within this resource group by specifying the desired image. Remember to replace myResourceGroup, myVM, and LinuxImageName with your actual resource group name, virtual machine name, and the specific Linux image you wish to use.

Manage VMs State in Azure Cloud Shell

Below is a table that outlines various Azure CLI commands for managing the state of virtual machines (VMs) in Azure:

TaskAzure CLI Commands
Start a VMaz vm start --resource-group myResourceGroup --name myVM
Stop a VMaz vm stop --resource-group myResourceGroup --name myVM
Deallocate a VMaz vm deallocate --resource-group myResourceGroup --name myVM
Restart a VMaz vm restart --resource-group myResourceGroup --name myVM
Redeploy a VMaz vm redeploy --resource-group myResourceGroup --name myVM
Delete a VMaz vm delete --resource-group myResourceGroup --name myVM

Make sure to replace myResourceGroup and myVM with your actual resource group and virtual machine names when executing these commands.

Get VMs Info in Azure Cloud Shell (CLI)

Here is a table detailing Azure CLI commands to retrieve information about virtual machines (VMs), their usage, and available sizes within a specified location:

TaskAzure CLI Commands
List VMsaz vm list
Get information about a VMaz vm show --resource-group myResourceGroup --name myVM
Get usage of VM resourcesaz vm list-usage --location eastus
Get all available VM sizesaz vm list-sizes --location eastus

Managing VM Disks and Images in Azure Cloud Shell

Here’s a table detailing Azure CLI commands for managing virtual machine (VM) disks and images, providing a comprehensive guide:

TaskAzure CLI Commands
Add a data disk to a VMaz vm disk attach --resource-group myResourceGroup --vm-name myVM --disk myDataDisk --size-gb 128 --new
List attached disks to a VMaz vm show --resource-group groupName --name vmName --query "storageProfile"
Remove a data disk from a VMaz vm disk detach --resource-group myResourceGroup --vm-name myVM --disk myDataDisk
Resize a diskaz disk update --resource-group myResourceGroup --name myDataDisk --size-gb 256
Snapshot a diskaz snapshot create --resource-group myResourceGroup --name mySnapshot --source myDataDisk
Create image of a VMaz image create --resource-group myResourceGroup --source myVM --name myImage
Create VM from imageaz vm create --resource-group myResourceGroup --name myNewVM --image myImage

Remember to replace placeholders like myResourceGroup, myVM, myDataDisk, groupName, vmName, mySnapshot, and myImage with your specific resource group names, VM names, disk names, snapshot names, and image names as applicable to your Azure environment.


Frequently Asked Questions (FAQs)

Can I switch between Bash and PowerShell in Azure Cloud Shell?
Yes, you can easily switch between Bash and PowerShell within Azure Cloud Shell. There’s an option at the top of the Cloud Shell session window that allows you to select your preferred shell experience.

Is Azure Cloud Shell free to use?
Azure Cloud Shell is provided at no additional charge. However, you may incur costs associated with the Azure resources managed through Cloud Shell, and the persistent storage required for Cloud Shell’s operation is billed according to regular Azure Storage rates.

How secure is Azure Cloud Shell?
Azure Cloud Shell is built on Azure’s secure infrastructure, ensuring a high level of security. It automatically authenticates with your Azure services, providing a secure management environment. Additionally, Azure role-based access control (RBAC) and Azure Active Directory ensure that only authorized users can access your Azure resources.

How do I save files created in Azure Cloud Shell?
Files created in Azure Cloud Shell are stored in a mounted Azure file share, ensuring that your data persists across sessions. You can also use Azure Cloud Shell’s integrated Git support to clone and manage repositories, which provides another method to save and manage your files.

What happens to my session if I am inactive in Azure Cloud Shell?
Azure Cloud Shell sessions are subject to a timeout after a period of inactivity. However, your environment and files persist across sessions thanks to the Azure file share attached to your Cloud Shell session, allowing you to pick up where you left off when you return.


Conclusion

Azure Cloud Shell stands as a transformative tool in the realm of cloud computing, offering an unparalleled level of accessibility in managing Azure resources. With its robust set of features, including the flexibility of Bash and PowerShell environments, integrated text editing, and direct browser-based access, Cloud Shell enables users to perform a range of cloud management tasks effortlessly.

The Azure CLI commands and PowerShell cmdlets provided within Cloud Shell are comprehensive and cover a vast array of tasks from managing VMs and their disks to handling networking and security aspects. The command cheat sheets and FAQs offered in this guide aim to serve as your go-to reference, simplifying your daily operations and enhancing your productivity.

How can we help?

Tired of your cloud costs building up? Don’t let cloud costs weigh you down anymore. With Economize, you can slash your cloud expenditures by up to 30% effortlessly. Book a free demo with us today and discover how we can help you start saving in as little as 10 minutes.

Adarsh Rai

Adarsh Rai, author and growth specialist at Economize. He holds a FinOps Certified Practitioner License (FOCP), and has a passion for explaining complex topics to a rapt audience.