The Azure Cloud Shell offers the ability to manage cloud resources, virtual machines, run scripts and other tasks directly from within the browser or Azure Mobile app. There are a few command-line tools for automating tasks and scripting things with Microsoft Azure. These tools are great to use locally or from a remote server, and the Azure Cloud Shell includes many of these tools pre-installed and ready to use. Azure Cloud Shell offers many powerful features that make it a really great tool for Azure Administrator, Developers, DevOps Engineers, Site Reliability Engineers, and others who need to work with Azure resources and manage their cloud environments. In this article, we’ll dive into many of the features of the Azure Cloud Shell that help you be more productive in your Azure management duties through.

Let’s get started!



What is the Azure Cloud Shell?

The Azure Cloud Shell is an embedded terminal / command-line interface that can be used within a web browser, or even the Azure Mobile app. The Azure Cloud Shell enables you to easily use both Bash and PowerShell directly in the browser or Azure Mobile app.

On the surface, the Azure Cloud Shell is simply a Bash or PowerShell prompt within the browser. If you look closer, you’ll see there are many more features made available that turn this experience into an extremely powerful scripting and management tool. Among these features is the support for automatically authenticating you with the Azure CLI and Azure PowerShell tools, since you are already authenticating with Azure AD in order to access the Cloud Shell in the first place. Some of the other features include support for popular open source tools, and file storage persistence across multiple sessions of the Cloud Shell.



Open Azure Cloud Shell within Azure Portal

The Azure Cloud Shell can be used directly within the Azure Portal. To open it, you simply click on the Cloud Shell icon in the header bar of the Azure Portal, and it will open the Cloud Shell in a pane at the bottom of the browser. Then once open, you will be able to toggle between either a Bash prompt or PowerShell prompt, in addition to having access to all the many features of the Cloud Shell.

Azure Cloud Shell Tips and Tricks 12
Screenshot: Azure Cloud Shell within Azure Portal

Open Azure Cloud Shell Stand-alone

The Azure Cloud Shell is also able to be used as a stand-alone experience by navigating to the https://shell.azure.com address. This enables the same Cloud Shell to be used, but without the Azure Portal interface components cluttering up your browser screen. The experience of the Cloud Shell here is something similar to a traditional terminal / command-line instance open on your local computer with the window being dedicated to the scripting experience.

Azure Cloud Shell Tips and Tricks 13
Screenshot: Azure Cloud Shell open in new tab, stand-alone

How is the Azure Cloud Shell hosted?

The Azure Cloud Shell is a feature offered by Microsoft for Azure cloud management, similarly to how the Azure Portal is offered for the same goal. As a result, the Azure Cloud Shell is a free feature any customer of Azure can use. The compute resources necessary for running the Azure Cloud Shell are not billed to you, so you do not need to worry about incurring Virtual Machine or other compute costs when using the Azure Cloud Shell.

Even though the Azure Cloud Shell is accessible within the browser, it’s not an emulated terminal / command-line experience. When you open the Azure Cloud Shell, Microsoft Azure actually spins up an Ubuntu Server Docker container behind the scenes and gives you access to it’s terminal. This latest information I’ve heard is this container is spun up using Azure Container Instances (ACI) in the backend, hidden from your view.

When running the Azure Cloud Shell, you can easily check the version of Ubuntu Server that it’s running by using the lsb_release -a command. This will show you that (at the time or writing this) the Azure Cloud Shell is running on Ubuntu 16.04 LTS.

Azure Cloud Shell Tips and Tricks 14
Screenshots: Bash and PowerShell showing Azure Cloud Shell Ubuntu version

Since the Azure Cloud Shell compute resources are free for you to use, it’s not built to persist machine state across sessions. However, when you startup a session within Azure Cloud Shell, it connects to an Azure Storage Account within your own Azure Subscription (that you do pay for) to persist any files you save to the local home directory (ala cd ~) on the container.

When you remain inactive in the Azure Cloud Shell, your session will time out after 20 minutes of inactivity. This will result in the underlying container hosting your session to be terminated and cleaned up. When you connect to the Azure Cloud Shell to open a new session again, it will fire up a new container instance for you. When this new container instance is started, it will connect to the same Azure Storage Account in your Azure Subscription, so you maintain access to any saved files within the local home directory.

P.S. If anyone on the Azure Cloud Shell product team at Microsoft wants to add clarity to how the Azure Cloud Shell is hosted, I look forward to connecting. The technical details I’ve explained here are a combination of what I’ve observed using the Cloud Shell, in addition to things I’ve heard through presentations over the years from various conference talks. Sorry, I don’t have source links to share.

Common Linux Commands

With the Azure Cloud Shell being powered by Ubuntu Linux, there are many of the usual Linux commands available for use within the shell. This is something that applies to both the Bash and PowerShell prompts within Azure Cloud Shell; as both are hosted on the same Ubuntu Linux host container.

Here are just a few of the common Linux commands that can be used. Keep in mind this is just a small subset, as there are MANY Linux commands that can be used within the Azure Cloud Shell environment:

# COMMON FILE SYSTEM COMMANDS

# List files in current directory
ls

# Create directory
mkdir

# Output file contents to the terminal
cat [filename]

# Delete a file
rm [filename]

# Change directories
cd [dir-name]
cd ..

# Navigate back to home directory
cd ~

In addition to the file / directory commands, there is support for several Linux tools included in the Azure Cloud Shell too. This includes support for manual pages, vim and nano editors, and other tools.

# Open a file in VIM editor
vi [filename]

# Open a file in Nano editor
nano [filename]

# Generate SSH key pair using RSA encryption
ssh-keygen -m PRM -t rsa -b 4096

# Secure shell connection to remote machine
ssh [username]@[ip-address]

# Execute a shell script
bash script.sh
./script.sh

# Display manual pages for specific commands
man ls
man rm
Azure Cloud Shell Tips and Tricks 15
Screenshot: Nano editor open within the Azure Cloud Shell

Keep in mind that the PowerShell experience in the Azure Cloud Shell also runs within the same Ubuntu Linux VM container. This means that in addition to using PowerShell commands, you will also be using Linux commands within the Azure Cloud Shell PowerShell experience. For example, you can use the nano editor from PowerShell within the Azure Cloud Shell too.

Azure Cloud Shell Tips and Tricks 16
Screenshot: Nano editor open within Azure Cloud Shell PowerShell

Secure Shell (SSH)

In the Linux world, SSH (aka Secure Shell) is used for remoting into other Linux machines. The Azure Cloud Shell includes support for ssh so you can use it to remote into other Linux machines directly from the Azure Cloud Shell.

chris@Azure:~$ ssh [username]@[server-address]

This is an extremely helpful tool to use for managing Virtual Machines in Azure.

Tip: SSH allows you to use either a Password or a SSH Key (public/private key pair) to securely connect to Linux machines. Microsoft Azure supports this with Linux VMs.

Download and Upload Files

With Azure Cloud Shell’s file system, you need to have a way to create files and download files too. The Azure Cloud Shell support a couple options for doing this. This includes a download command for downloading files from the Azure Cloud Shell, and the usual Linux commands (ala wget and curl) for running commands on the VM to download files to it. Plus, the Azure Cloud Shell includes a feature that allows you to directly upload files from your local file system into the Azure Cloud Shell environment.

Upload file to Azure Cloud Shell

The Azure Cloud Shell interface includes file upload capabilities that let you select files from your local file system and upload them into the Azure Cloud Shell file system. Within the Azure Cloud Shell, simply click the upload / download files button, then select Upload to initiate the process.

Azure Cloud Shell Tips and Tricks 17
Screenshot: Azure Cloud Shell file upload

Another option to “upload” file to the Azure Cloud Shell file system is to use the wget and curl Linux commands within the Azure Cloud Shell environment to download files to the file system using Internet addresses. This isn’t really uploading, but it still is a great way to be able to get files copied to the Azure Cloud Shell that you might need to work with there.

# Download file using wget Linux command
wget http://[file-url]

# Download file using curl Linux command
curl http://[file-url] >> [filename]

Download files from Azure Cloud Shell

The Azure Cloud Shell interface includes file download capabilities that let you specify files in the Azure Cloud Shell file system and download them locally. Within the Azure Cloud Shell, simply click the upload / download files button, select Download, then specify the path to the file in the Azure Cloud Shell you wish to download.

Azure Cloud Shell Tips and Tricks 18
Screenshot: Azure Cloud Shell file download

Additionally, the Azure Cloud Shell includes a command that can be run in the terminal to download a file from the Azure Cloud Shell file system. Simply run the download command passing it the name of the file to download.

chris@Azure:~/tf$ download deploy.tf

Azure Cloud Shell Editor

In addition to the ability to use Linux command-line editors within the Azure Cloud Shell, you can also use the built-in Azure Cloud Shell Editor based on VS Code. To use the built-in editor, use the code command followed by the name of the file to edit. The editor also includes a file explorer style functionality that enables you to edit multiple files more quickly.

Code / File Editor

To use the built-in file editor, use the code command followed by the name of the file to edit. This give you a more graphically appealing experience for editing files within the Azure Cloud Shell.

Here’s an example command for opening a file using the code command to open the Azure Cloud Shell Editor:

chris@Azure:~/tf$ code deploy.tf

Once the code command is executed, the Azure Cloud Shell Editor will open the file specified and allow you to edit it. You can use this command to both edit existing files and create new files. The editor will display syntax highlighting for common code file types to help with the editing experience.

Azure Cloud Shell Tips and Tricks 19
Screenshot: Azure Cloud Shell Editor with a Terraform .tf file open

Clicking on the ellipsis button in the top-right of the Azure Cloud Shell editor will expose options for save, close, and open file actions.

Azure Cloud Shell Tips and Tricks 20
Screenshot: Azure Cloud Shell menu

Alternatively, you can also use keyboard shortcuts for actions like save and close:

  • Save File – Windows: Ctrl-S – macOS: Cmd-S
  • Close File – Windows: Ctrl-C

Note: The Azure Cloud Shell Editor may look similar to VS Code and include syntax highlighting, but it’s not the full VS Code experience. For example, the Azure Cloud Shell Editor does not support extensions like VS Code does.

File Explorer

The Azure Cloud Shell Editor can be opened by passing a period argument to open the editor in a “file explorer” mode. This can be used to more easily explore files in the directory, or to more quickly edit multiple files. This will open the current directory in the editor, allowing a view of all the sub-directories and files within the current directory.

chris@Azure:~/tf$ code .
Azure Cloud Shell Tips and Tricks 21
Screenshot: Azure Cloud Shell Editor file explorer mode

Clicking on files within the “file explorer” pane of the Azure Cloud Shell Editor will open those files in the file editor. You can then save any file changes, then select a new file for editing without having to close and reopen the Azure Cloud Shell Editor.

Pre-Installed Apps and Tools

The Ubuntu Linux VM that powers the Azure Cloud Shell includes pre-installation and support for several different tools and programming languages that are commonly used. The allows you to use things like the Azure CLI, git, kubectl, dotnet, or python without needing to install anything; all from within the Azure Cloud Shell cross-platform, browser-based experience.

Azure Cloud Shell Tips and Tricks 22
Screenshot: Terraform command in Azure Cloud Shell

Here’s a list of the various tools and apps pre-installed for your use in the Azure Cloud Shell:

  • Linux tools
    • bash
    • zsh
    • sh
    • tmux
    • dig
  • Azure tools
    • Azure CLI
    • Azure PowerShell (in the PowerShell experience)
    • AzCopy
    • Azure Functions CLI
    • Service Fabric CLI
    • Batch Shipyard
    • Blobxfer
  • Text Editors
    • code (via Azure Cloud Shell Editor)
    • vi
    • nano
    • emacs
  • Source Control
    • git
  • Build tools
    • make
    • maven
    • npm
    • pip
  • Containers
    • Docker machine
    • Kubectl
    • Helm
    • DC/OS CLI
  • Databases
    • MySQL Client
    • PostgreSQL Client
    • sqlcmd Utility
    • mssql-scripter
  • Other tools
    • iPython Client
    • Cloud Foundry CLI
    • Terraform
    • Ansible
    • Chef InSpec
    • Puppet Bolt
    • HashiCorp Packer
    • Office 365 CLI
  • Programming Languages
    • .NET Core
    • Go
    • Java
    • Node.js
    • Python
    • PowerShell

Wrap Up

The Azure Cloud Shell offers a really great browser-based, cross-platform experience for scripting and managing resources within the Microsoft Azure cloud. It’s easy to open directly from the Azure Portal or stand-alone, and does not require you to install anything to use. All you need is an Azure Subscription to use the Azure Cloud Shell, and the Cloud Shell is included Free to use just as the Azure Portal is. There’s no need to pay for the underlying VM that runs the Azure Cloud Shell. All this makes the Azure Cloud Shell extremely easy to use and a really great tool to use for all your resource and VM management needs.


Microsoft MVP

Chris is the Founder of Build5Nines.com and a Microsoft MVP in Azure & IoT with 20 years of experience designing and building Cloud & Enterprise systems. He is also a Microsoft Certified: Azure Solutions Architect, developer, Microsoft Certified Trainer (MCT), and Cloud Advocate. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.