Accessing and Using the Azure Cloud Shell

Hands-On Lab

 

Photo of Jason Calton

Jason Calton

Training Architect

Length

00:30:00

Difficulty

Beginner

This hands-on lab will introduce you to Azure Cloud Shell, a web-based virtual terminal that allows you full access to Azure PowerShell and the CLI — right from your browser! - Nothing to install - No plug-ins - Just scripting goodness! We'll take a look at how to set up Cloud Shell and run a few commands in both the Azure CLI and Azure PowerShell. When we're finished, you'll have the knowledge necessary to run Cloud Shell in your own Azure subscription. ## Key Objectives - Configure the Azure Cloud Shell - Run sample commands in Azure CLI (Bash) - Create a Linux virtual machine using the Azure CLI (Bash) - View Azure resources in Azure PowerShell - Remove a Linux virtual machine using Azure PowerShell ## Helpful Links - Azure CLI Overview: https://docs.microsoft.com/en-us/cli/azure/?view=a - Azure CLI Reference: https://docs.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest - Azure PowerShell Overview: https://docs.microsoft.com/en-us/powershell/azure/overview?view=azps-1.6.0 - Quickstart for Bash in Azure Cloud Shell: https://docs.microsoft.com/en-us/azure/cloud-shell/quickstart - Quickstart for PowerShell in Azure Cloud Shell: https://docs.microsoft.com/en-us/azure/cloud-shell/quickstart-powershell

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Accessing and Using the Azure Cloud Shell

Introduction

In this hands-on lab, we will learn how to use Azure Cloud Shell, a web-based virtual terminal that gives us full access to Azure PowerShell and the Azure CLI from within a browser. We'll take a look at how to set up Cloud Shell and run a few commands in both the Azure CLI and Azure PowerShell.

We will complete the following tasks:

  • Configure the Azure Cloud Shell
  • Run sample commands in the Azure CLI (Bash)
  • Create a Linux virtual machine using the Azure CLI (Bash)
  • View Azure resources in Azure PowerShell
  • Remove a Linux virtual machine using Azure PowerShell

Log in to the Azure Portal using the credentials provided on the lab instructions page.

Configure Cloud Shell

  1. In the Azure Portal, click the Cloud Shell icon (>_) in the top right corner of the screen.
  2. In the Cloud Shell welcome menu, click Bash.
  3. In the storage menu, click Show advanced settings.
  4. Under Storage account, choose the Create new option, and enter a unique name in the text box below (e.g., "a900storage1").
  5. Under File share, choose the Create new option, and type "cloudshell" in the text box below.
  6. Leave Subscription, Resource group, and Location set to their default values.
  7. Click Create storage.

Execute Commands in the Bash Shell

  1. List the resource groups available in our Azure subscription.
    az group list
  2. List the storage accounts available in our Azure subscription.
    az storage account list
  3. List the virtual machines available in our Azure subscription.
    az vm list

Create a Virtual Machine using Bash and the Azure CLI

  1. Run the following command (remember to replace <RESOURCE_GROUP> with the actual name of your lab resource group):
    az vm create --resource-group <RESOURCE_GROUP&gt --name myVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys
  2. Minimize Cloud Shell, and click Virtual machines in the left sidebar of the Azure Portal.
  3. You should see myVM in the list of virtual machines.
  4. Go back to Cloud Shell.
  5. Connect to the virtual machine via SSH. (Make sure to replace <VM_PUBLIC_IP> with the value from the output of the previous command.)
    ssh azureuser@<VM_PUBLIC_IP&gt
  6. Type yes at the prompt, and press Enter.
  7. Type exit, and press Enter to log out.

Run Cmdlets in the Azure PowerShell

  1. Click Bash in the upper left corner of Cloud Shell, and select PowerShell from the dropdown.
  2. Click Confirm.
  3. List the resource groups available in our Azure subscription.
    Get-AzResourceGroup
  4. List the storage accounts available in our Azure subscription.
    Get-AzStorageAccount
  5. List all the resources that now exist in the lab.
    Get-AzResource | ft

Remove the Virtual Machine

  1. Run the following command:
    Remove-AzVM -Name myVM -ResourceGroupName <RESOURCE_GROUP_NAME>
  2. Type Y at the prompt, and press Enter.
  3. Verify that the virtual machine has been deleted.
    Get-AzResource | ft
  4. Type exit, and press Enter.
  5. Click Quit to close Cloud Shell and return to the Azure Portal.

Conclusion

Congratulations, you've successfully completed this hands-on lab!