Everything you need to know about Azure Cloud Shell: Features, use cases, and troubleshooting

Having an admin-friendly, feature-rich shell interface is crucial for effectively managing today’s complicated and dynamic cloud environments. Azure Cloud Shell is one such tool. It provides secure and centralized access to Azure environments, allowing administrators to perform everyday tasks, manage resources, and automate workflows.

This article dives deep into everything you need to know about Azure Cloud Shell, covering its definition, features, use cases, getting started guide, and troubleshooting tips. By the end, you’ll be well equipped to leverage Azure Cloud Shell to streamline your cloud administrative duties.

What is Azure Cloud Shell?

Azure Cloud Shell is a browser-based, interactive shell environment specifically designed for managing Azure resources. It provides a familiar command-line experience that’s accessible from virtually any device with a web browser and an internet connection. This makes it incredibly convenient for on-the-go administration.

Here are some stand-out features of Azure Cloud Shell:

  • Shell environment of choice: You can choose between using a shell environment powered by either Bash or PowerShell. This minimizes the learning curve and gives you the flexibility to work with your preferred scripting language.
  • Out-of-the-box support for many languages and tools: Azure Cloud Shell natively supports several common tools, including Linux tools like bash, zsh, and dig; text editors like Vim, nano, and Emacs; cloud management tools like kubectl, Ansible, and Terraform; build tools like Make, Maven, and npm; source control tools like git and GitHub CLI; database tools like MySQL client and PostgreSQL client; and programming languages/frameworks like Java, Node.js, and Go.
  • Automatic authentication: Cloud Shell integrates with your Azure subscription, automatically authenticating you upon launch. This saves you the time and effort of manually entering credentials each time you need to manage your Azure resources.
  • Multiple access points: Users can invoke the Azure Cloud Shell from several access points, including the Azure Portal, Azure mobile app, shell.azure.com, and the VS Code Azure Account extension.
  • Persistent storage: Cloud Shell offers persistent storage through an attached Azure Files share. This allows you to save your files, configurations, and scripts between sessions, ensuring a more streamlined workflow.
  • Integrated text editor: Cloud Shell includes a built-in, intuitive text editor that’s based on the open-source Monaco editor. This means that you can create and edit scripts directly within the Cloud Shell environment, eliminating the need to switch between applications.

Use cases of Azure Cloud Shell

Here’s a glimpse of what you can achieve with Azure Cloud Shell:

  • Provision and manage virtual machines, storage accounts, databases, and other Azure resources.
  • Run Azure CLI or Azure PowerShell cmdlets to automate complex deployments and configurations.
  • Troubleshoot and diagnose different issues within the environment by leveraging native integrations with different services and tools.
  • Use pre-installed language compilers and interpreters to develop and test code directly within the shell environment.
  • Execute Ansible playbooks for automating configuration management tasks across your Azure infrastructure.
  • Use Terraform to define, manage, and provision infrastructure as code, enabling streamlined deployment and management of Azure resources.

Getting started with Azure Cloud Shell

Next, let’s explore the steps to take to get started with Cloud Shell.

Step 1 – Registering the resource provider

Start by registering the Microsoft.CloudShell resource provider. Here’s what you need to do:

  • Log into the Azure portal.
  • From the portal menu, search for and select “Subscriptions”.
  • Choose the relevant subscription.
  • From the left menu, choose “Settings -> Resource providers”.
  • In the search box on the “Resource providers” tab, input the text “cloudshell”.
  • “Microsoft.CloudShell” should appear in the search results. Select it.
  • Finally, change the status of the provider to “Registered”.

Step 2 – Launch Cloud Shell

With the resource provider registered, we are ready to launch Cloud Shell:

  • You’ll see a terminal-shaped icon on the top navigation tab of the portal. Click it to launch the Cloud Shell.
  • Since this is your first time accessing the shell, you will be asked to set up an Azure storage account. This will be used to enable persistence via an Azure file share.
  • Here, you should choose the subscription that was used for creating the storage account and file share.
  • Finally, click the “Create storage” button.

Note that this will create a standard storage account that supports up to 5GBs of storage. If needed, you may choose the premium account that supports up to 100GBs.

Step 3 – Choose the preferred shell environment

With the Cloud Shell launched, you can easily switch between Bash or PowerShell environments. To do so, click on the dropdown on the top left, and choose the environment you want.

Step 4 – Set the subscription

Before you start performing any tasks on the shell, you must set your subscription. Here’s what you need to do:

  • Get a list of available subscriptions using this command:
    az account list
  • After selecting the relevant subscription from the output, enable it via this command:
    az account set --subscription ‘name-of-the-subscription'

A quick overview of the shell environment

Now that we have set up and configured our Cloud Shell, here’s an overview of how to perform some basic operations.

  • To see a list of all commands available on the Azure CLI, simply run:
    az
  • To get features like auto-complete, command descriptions, and examples, run this command:
    az interactive
  • To receive real-time recommendations for the next command, based on your execution history, use this command:
    az next
  • To get tabular output for any command, simply include the --output table option. For example, you can get tabular output for the az account command by running this:
    az account list --output table
  • If you wish to run the Azure CLI in a containerized Docker environment, use this command:
    docker run -it mcr.microsoft.com/azure-cli
  • To get help for any command, simply include the --help option. For example, you can get help for the az account command by running this:
    az account --help
  • To restart a Cloud Shell session, simply click the restart icon from the Cloud Shell toolbar.
  • To modify the text size, follow these steps:
    • Click the settings icon from the Cloud Shell toolbar.
    • Hover your cursor over “Text size” and then choose the desired size setting.
  • To upload or download a file, click the download-upload icon on the Cloud Shell toolbar and select the relevant option.
  • For copy/pasting, follow these instructions:
    • On Windows machines, use Ctrl + C for copying and Shift + Insert for pasting.
    • On MacOS, use Cmd + C for copying and Cmd + V for pasting.
    • On Linux, use Ctrl + C for copying and Ctrl + Shift + V for pasting.
  • To end the current session, simply run the exit command.

How to use the integrated text editor

The integrated text/file editor is a great way to modify source code without having to leave the shell environment. The editor contains several handy features like language highlighting and a file explorer. To invoke the editor, simply run the following command:

code .

The above command will open your current working directory in the editor. It’s also possible to edit a single file within the editor. To do so, issue this command:

code <name-of-the-file>

To exit the editor, click the icon on the top right and select “Close editor”.

Working with Predictive IntelliSense

Since January 2023, Cloud Shell for PowerShell comes with Predictive IntelliSense enabled by default. This feature provides auto-complete suggestions that can be handy when debugging or performing urgent tasks.

Predictive IntelliSense can show suggestions inline (mode: InlineView), or as a list on the next line (mode: ListView). Based on your preferences, you can switch between the modes by pressing the F2 key.

It’s also possible to change the color of the offered suggestions. For example, you can use the following command to set a black foreground and a dark red background.

code <name-of-the-file>

If you wish to disable Predictive IntelliSense, just run this command:

Set-PSReadLineOption -PredictionSource None

Creating a MySQL server

As mentioned above, Cloud Shell allows you to leverage several built-in integrations to perform common administrative tasks. For example, here’s how you can create a MySQL server by issuing Azure CLI commands directly from the Cloud Shell.

  • Start by creating a resource group that will be associated with our MySQL server.
    az group create --name sampleRG --location westus
  • Use the az mysql server create command to initialize the new server within our new resource group.
    az mysql server create --resource-group sampleRG --name demo --location westus --admin-user admin --admin-password <password-here> --sku-name GP_Gen5_24

Best practices for secure Azure Cloud Shell usage

Follow these best practices to prevent unauthorized access and reduce your attack surface:

  • Strengthen the security of your Azure account by enabling two-factor authentication (2FA).
  • Use Azure Role-based access control (RBAC) to grant users only the minimum permissions required to perform their tasks within Cloud Shell. This principle of least privilege minimizes the potential damage if a user's credentials are compromised.
  • Avoid using Cloud Shell on untrusted public Wi-Fi networks. Public networks can be susceptible to eavesdropping, so it's best to use Cloud Shell only over secure connections.
  • Regularly monitor your Azure activity logs to identify any suspicious access or activity within your Cloud Shell environment.
  • Implement secure coding practices when writing scripts for use within Cloud Shell. For example, avoid hardcoding credentials and using environment variables for sensitive information.
  • Always log out of your Cloud Shell session when you're finished working. This helps prevent unauthorized access if your device is left unattended.

Performing advanced tasks with Azure Cloud Shell

In the following sections, we will look at how you can perform a few advanced tasks on the Azure Cloud Shell.

Managing cloud resources

Here are some examples of how you can manage cloud resources from the shell:

  • To retrieve all your resource groups, including their names and locations, use:
    az group list
  • To create a new virtual machine, use:
    az vm create \
    --resource-group MyResourceGroup \
    --admin-username $MY_USERNAME \
    --name MyVm \
    --image UbuntuLTS \

    Don’t forget to update the above options per your requirements.

  • To list all your storage accounts, use:
    az storage account list

Similarly, you can create new storage accounts, manage access keys, and interact with storage blobs and containers using Azure CLI commands within the Cloud Shell.

Updating your file share

It’s also possible to update the file share associated with the Cloud Shell. To do so, you can use the clouddrive mount command. Before you start, double check the file share that’s currently mounted by running the df command. The output of the command includes the name of the storage account and the file share.

Here’s how you can change the file share:

clouddrive mount -s yourSubscription -g yourRG -n nameOfStorageAcc -f nameOfFileShare

You will have to specify your subscription, resource group, storage account, and file share in the above command.

At any time, if you want to get more information on the clouddrive mount command, just run this command:

clouddrive mount -h

Deploying Azure resources using cloud templates

Azure Resource Manager (ARM) templates provide a declarative way to define the infrastructure for your Azure resources. Using Cloud Shell, you can deploy these templates with ease. Here’s the command to do so:

az deployment group create \
--resource-group <resource-group-name> \
--template-file <template-file-path> [or --template-uri <template-url>] \
--parameters <parameters-file> (optional)

The --template-file option expects either a path to a locally saved template file, or a URL to a remote template file.

Azure Cloud Shell troubleshooting

Finally, we will share some common Azure Cloud Shell issues and how you can go about troubleshooting them.

Installation or access issues

Problem: You're unable to launch Cloud Shell or face an error message during initialization.

Troubleshooting steps:

  • Visit the Azure Status page (https://azure.microsoft.com/en-us/get-started/azure-portal/service-health) to see if there are any reported outages that may be impacting Cloud Shell.
  • Try clearing your browser cache and cookies, then relaunch Cloud Shell.
  • In rare cases, there may be browser-specific compatibility issues. Try launching Cloud Shell using a different web browser.
  • Certain browser extensions can interfere with Cloud Shell functionality. Try disabling any recently installed extensions and relaunch Cloud Shell.

Authentication problems

Problem: You face an error message related to authentication or authorization while using Cloud Shell.

Troubleshooting steps:

  • Ensure that you're signed into the Azure portal using the Azure subscription with the necessary permissions to access Cloud Shell resources.
  • If Multi-Factor Authentication (MFA) is enabled for your Azure account, you may need a secondary verification code during sign-in within Cloud Shell.
  • Make sure you have a stable internet connection and that there are no firewall restrictions blocking access to Azure resources.
  • Sometimes, refreshing your Azure login credentials within Cloud Shell can resolve authentication issues. Use the az account logout command followed by the az login command to re-authenticate.

Slow performance

Problem: You experience sluggish performance or lag within the Cloud Shell environment.

Troubleshooting steps:

  • Multiple Cloud Shell sessions or open tabs can consume resources and slow down performance. Close any inactive sessions or tabs.
  • Verify that your internet connection speed is not the bottleneck by running network diagnostics.
  • Sometimes, a simple restart of your Cloud Shell session can resolve temporary performance issues. Use the power button in the Cloud Shell interface to restart.
  • The free tier of Cloud Shell comes with limited storage. If you're working with large files or scripts, consider upgrading your storage quota for improved performance.

Command-line issues

Problem: You face errors or unexpected behavior when running commands within Cloud Shell.

Troubleshooting steps:

  • Double-check the syntax of your commands for any typos or missing arguments.
  • Ensure the specific command-line tool you're using (e.g., Azure CLI version) is installed and configured correctly within your Cloud Shell environment.
  • Outdated versions of Azure CLI or Azure PowerShell might have bugs or compatibility issues. Use the az update or Update-AzModule commands (depending on the tool) to update them to the latest version.

Storage access issues

Problem: You face issues in accessing or modifying files within your Cloud Shell storage.

Troubleshooting steps:

  • Make sure you have the necessary permissions to access and modify files within your Cloud Shell storage (attached Azure Files share).
  • Remember that the free tier of Cloud Shell has storage limitations. Verify that you haven't exceeded your quota, which can prevent file access or modification.
  • Occasionally, reconnecting to your Cloud Shell storage can resolve access issues. Use the az storage account show-connection-string command to get the connection string and reconnect.

Integration issues

Problem: You experience errors or unexpected behavior when using Cloud Shell with other Azure services or tools.

Troubleshooting steps:

  • Visit the Azure Status (https://azure.microsoft.com/en-us/get-started/azure-portal/service-health) page to see if there are any reported outages impacting the specific Azure service you're trying to integrate with.
  • Ensure that you're properly authenticated within Cloud Shell and have the necessary permissions to access the relevant Azure service resources.
  • Refer to the documentation for the specific Azure service you're using. Ensure that you're following the correct steps to integrate it with Cloud Shell.

Conclusion

Azure Cloud Shell is an administrator-friendly, customizable shell for managing Azure cloud environments. In today’s article, we covered everything you need to know about the tool; from its purpose and use cases to handy commands and integrations. We hope you found it insightful.

To ensure that your Azure Cloud infrastructure remains secure and performant, check out the comprehensive Azure monitoring tool by Site24x7.

Was this article helpful?

Related Articles

Write For Us

Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 "Learn" portal. Get paid for your writing.

Write For Us

Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 “Learn” portal. Get paid for your writing.

Apply Now
Write For Us