Using Azure Cloud Shell

The Azure Cloud Shell allows you to run commands in Azure without installing any additional software on your computer. All that you need is a web browser. If you have the Azure mobile app, then you can run commands in Azure directly from your phone.

For instance, let’s say that you’re waiting for your flight at the airport while traveling to a conference showcasing the latest Azure features when you realize that you forgot to create a virtual machine (VM) as part of your task on a user story. You already have the command saved in a file on your laptop from creating the same VM a week ago, so you pull out your laptop, boot it up, log in to the Azure Portal, then execute the command in Azure Cloud Shell. After that, you close your laptop and board the plane.

Let’s do a walk-through of these steps using Azure Cloud Shell to create a VM. If this is the first time that you’ve used Azure Cloud Shell, then there are some prompts that you need to get through. So, let’s get to it.

Opening Cloud Shell

  1. Log in to the Azure Portal. If you don’t already have an Azure account, then you can create a free account by the steps here.
  2. Start Cloud Shell from the portal. It’s near the top.
  3. Select a subscription where the storage account will be created. Cloud Shell stores its persistent data there. The storage account will also incur a small monthly cost.
  4. Optional: Select “Show advanced settings” in order to specify a name for the resource group, storage account, and file share. Or, choose to use existing ones.
  5. Select “Create storage”.

Create VM

Select Bash as the language of choice for this session. If you prefer Azure PowerShell over Azure CLI, then you can use PowerShell, but the commands used here will be in Bash.

Before creating the VM, set the preferred subscription.

  1. Show subscriptions.
    az account list
  2. Choose a subscription from the list. It will be remembered for future sessions.
    az account set --subscription '<use-your-subscription-name>'
  3. Create a resource group to hold the new VM.
    az group create --location eastus --name CoolAppRg
  4. Create a Ubuntu VM.
    az vm create -n CoolVm -g CoolAppRg --image UbuntuLTS --generate-ssh-keys
    1. When the option --generate-ssh-keys is used, then SSH keys will be created and set up in the VM by the Azure CLI.
    2. The public and private keys are stored at /home/<user>/.ssh/, which is stored in the file share of the storage account that was created when you first started Cloud Shell.
  5. Optional: If you want to validate that the VM was created before letting your colleague know that it’s ready for use, then you can find the command to SSH into the VM by searching for the VM in the Azure portal search bar, then selecting “Connect”.

Delete the Resource Group

When it’s no longer needed, the resource group can be deleted with the following command.

az group delete -n CoolAppRg

Cloud Shell Storage Details

When the Azure Cloud Shell is first created with the basic settings, three resources will be created.

  • Resource group: cloud-shell-storage-<region>
  • Storage account: cs<uniqueGuid>
  • File share: cs-<user>-<domain>-com-<uniqueGuid>. This file share is mounted to your $Home directory.

If you ever wanted to clean out your Azure Cloud Shell settings, then delete one or more of these resources.

What Else Can It Do?

Creating a VM is only one example of what can be done. If you haven’t memorized all of the commands, then you can find more commands on the fly. Let’s say that you’re working with Azure AD. The most popular commands related to Azure AD can be found with this command.

az find ad

When you need to dig into the details of a command, use --help.

az ad --help

The above command will output subgroups, such as app. Let’s dig deeper.

az ad app --help

The show command is one of the commands that are listed. Digging deeper…

az ad app show --help

Now we get to the arguments of the command, such as –id. So, the final command could look like this.

az ad app show <object-id>

By using help, we were able to learn a lot about the az ad command without needing to memorize anything and without needing to do any searching in the web browser.

Conclusion

The Azure Cloud Shell is a powerful tool that allows you to use Bash or PowerShell commands to control Azure resources without needing to download or install any software. Additional commands can be found from within the Cloud Shell without needing to memorize them.