How do I access Azure cloud shell?

How to launch bash or PowerShell from the Azure portal? Azure offers cloud based shell access for advanced users almost from every corner. Microsoft maintains a cloud shell with commonly used CLI tools including Linux shell interpreters, PowerShell modules, Azure tools, text editors, source control, build tools, container tools, database tools, and more. Azure Cloud Shell also includes language support for several popular programming languages such as Node.js, .NET, and Python.

Enable Azure Cloud BASH shell

1. Login to Azure portal.

2. Click on the Cloud shell icon. Top right – > Next to the search bar. (highlighted)

How do I access Azure cloud shell?
Launch Azure Cloud shell

3. If you are familiar with bash, select bash shell to launch.

How do I access Azure cloud shell?
Bash Powershell – Azure Cloud Shell

4. Select the subscription and storage account. If you do not have existing storage account , you need to create a one.

The Microsoft Azure Cloud Shell is an interactive, browser-accessible shell for managing Azure resources. Azure Cloud Shell can be used from any modern web browser and the Azure Mobile App. It means that you don’t need to install any module on your workstation. You just have to open your web browser, connect to the Azure web portal and use the Cloud Shell.

To use Microsoft Azure Cloud Shell, you’ll need to have an Azure subscription and depending on what resources you use while logged in you may be charged. When you first sign up, you’ll need to have a resource group, storage account and Azure File Share associated with it.

Microsoft Azure Cloud Shell Support Languages

LanguageVersion.NET Core2.0.0Go1.9Java1.8Node.js8.9.4PowerShell6.2.0Python2.7 and 3.5 (default)

1 – Go to the Azure portal, and click on the portal to anyone by default directly from the Portal via the Icon below:

How do I access Azure cloud shell?

2 – Once clicked on the Icon you will see a new panel at the bottom of the browser then you can select for Powershell or Bash

How do I access Azure cloud shell?

3 – Now, you will be prompted to create a storage account in order to associate a new Azure File Share to continue files across sessions then click create storage

How do I access Azure cloud shell?
How do I access Azure cloud shell?

4 – Now successfully created for my cloud shell profile. So, At the top of the following screenshot, you can see the details below:

How do I access Azure cloud shell?

5 – OK, now see we have a terminal which is very similar to a Linux terminal

How do I access Azure cloud shell?

6 – To discover all available command run the following “AZ help” command

How do I access Azure cloud shell?

Good luck! Just give it try – I’m sure you’ll love it as well. If you have any comments or questions on feel free to contact me.

This year I am very busy, so couldn’t write the articles but today, I am back to help the techies community.

Tired of having to load client tools on your computer every time you want to manage something in Microsoft Azure Cloud? Look no further! Using the Azure Cloud Shell, all you need is a browser to manage Azure from the command line.

Not a reader? Watch this related video tutorial!

Not seeing the video? Make sure your ad blocker is disabled.

Command-line tools like Terraform, Azure CLI the Azure PowerShell module, and more are freely available right in your browser. In this article, you will learn how to set up and configure Azure Cloud Shell and see what tools it has in store.

Let’s get into it!

Table of Contents

  • Prerequisites
  • What is Azure Cloud Shell?
  • Setting Up The Azure Cloud Shell
  • Getting Cloud Drive Information
  • Accessing the Azure Drive to Navigate Azure Resources
  • Uploading A File To Azure via Cloud Shell
  • Accessing Command Line Tools Available in Cloud Shell
    • Cloning a Git Repository
    • Creating Resource Groups via Azure CLI
    • Running Terraform
  • Using The File Editor
    • Using the File Editor Command Palette
  • Testing Web Applications with the Web Preview
  • Miscellaneous Cloud Shell Actions
    • Managing Sessions
      • Restarting the Current Session
      • Starting a New Session
    • Changing Font and Font Size
  • Integrating Cloud Shell with Visual Studio Code
  • Conclusion

Prerequisites

  • An Azure Cloud account (Free Tier will work)
  • An Azure Storage Account which will incur a small cost for the storage of your files.
  • Visual Studio Code – This tutorial is using v1.58.
  • NodeJS – This tutorial is using v14.17.3.

What is Azure Cloud Shell?

The Azure Cloud Shell is a browser-accessible shell for managing Azure resources in Bash or PowerShell.

Azure Cloud Shell runs in a container or a lightweight image containing application software that can run on top of an operating system. When you start up a new Azure Cloud Shell, Azure creates a Linux container image and stores that container image stored in your storage account.

Since containers are transient, to store files over multiple sessions, Azure Cloud Shell creates an Azure file share to securely store your data files. Azure Cloud Shell mounts this file share in your Cloud Shell home directory or mounts the file share as a separate drive labeled “clouddrive”.

Setting Up The Azure Cloud Shell

Now that you know the basics of what Cloud Shell is and how it works, let’s get into spinning one up for the first time!

  1. Open your favorite web browser, navigate to the Azure portal, http://shell.azure.com and log into your Azure account, if required.

2. The first time you launch Cloud Shell, you’ll see the confirmation pop-up below. Set PowerShell as your default shell by clicking on PowerShell. You can optionally choose the Bash shell also but this tutorial will be using PowerShell.

How do I access Azure cloud shell?
Starting up of Cloud Shell

3. Now, click on Show advanced settings in the dialog box, as shown below.

You could just select Create Storage in this box, but in this tutorial, you’re going to drill a bit deeper into how Cloud Shell is configured and also how it works.

How do I access Azure cloud shell?
Accessing Advanced Settings

Fill in the required fields as explained below and click on Create Storage.

  • Subscription – The Azure subscription you’re creating all of the Cloud Shell resources under.
  • Cloud Shell Region – The region you’d like to deploy the Cloud Shell resources to.
  • Show vNet isolation settings – Allows the cloud shell to access virtual machines and other resources behind a firewall or using private addresses within Azure.
  • Resource Group, Storage Account, and File Share – Select any existing items here or select the Create new option and provide a name for each. This file share will be automatically mounted in your Cloud Shell session and called clouddrive.

How do I access Azure cloud shell?
Cloud Shell Advanced Settings

Once you’ve provided the required parameters, you’ll be dropped into your Azure Cloud Shell session. Since you previously set PowerShell as your default shell, you’ll be taken into a PowerShell environment, as shown below.

How do I access Azure cloud shell?
Active Cloud Shell Session

If you prefer working in a Bash environment, click on the drop-down option at the top-left corner of the shell and select Bash, as shown below.

How do I access Azure cloud shell?
Switching to a Bash Shell

Getting Cloud Drive Information

Now that you have Azure Cloud Shell running, it’s time to run some commands. You’re in a real shell with thousands of commands and utilities available but this tutorial is going to only focus on a few.

All commands will be run in the PowerShell console, but Bash provides similar functionality using the Azure CLI.

Let’s first inspect the clouddrive by running the PowerShell cmdlet

cd Azure:
1, as shown below. You’ll see that running the
cd Azure:
1 command returns various information about your clouddrive including the FileSharePath where you can access your clouddrive.

The FileSharePath property is where Azure Cloud Shell mounted the Azure file shared created when you were setting up the Cloud Shell.

Get-CloudDrive

How do I access Azure cloud shell?
Getting clouddrive Information

Accessing the Azure Drive to Navigate Azure Resources

The Azure Cloud Shell comes pre-loaded with various tools for you; one of those tools is the Azure drive. The Azure drive is a handy PowerShell drive that exposes your Azure resources as a file system based on Simple Hierarchy in PowerShell (SHiPS).

Related:Understanding and Building New PS Drives in PowerShell

1. Navigate to your Azure PS Drive by changing to the drive just as you would your file system. You can tell that you are now in the Azure drive from the Azure:\> prompt below.

cd Azure:

How do I access Azure cloud shell?
Accessing Azure Drive

2. Next, view your current Azure subscription by running Get-ChildItem or the PowerShell alias dir. Notice below that the current subscription is Pay-As-You-Go.

How do I access Azure cloud shell?
Results for dir

3. Drill down deeper by changing to the Pay-As-You-Go “folder” and run dir again to view its contents.

cd ./Pay-As-You-Go/
dir

In the image below, you’ll see all Azure resources available in your subscription.

How do I access Azure cloud shell?
Viewing Azure Resources

For more examples of navigating around Azure resources, look at the Azure PSDrive repository on GitHub.

4. Now, navigate to any of your Azure resources by running the command below, replacing <resources> with your preferred resources name.

cd ./<resources>

For example, you can navigate to the Cloud Shell’s Azure Files share by going through the storage account the file share is created on, as shown below.

cd ./StorageAccounts/<storageaccountname>/Files/cloudgroup
dir

How do I access Azure cloud shell?
All Resources in Azure

All Resources in Azure

Uploading A File To Azure via Cloud Shell

You have a clouddrive ready to store files so let’s now upload some to it and see how that works.

  1. Pick or create a file on your local machine. This tutorial will use a file called mycloudshelltextfile.txt.

2. Click on the upload/download icon in the Cloud Shell toolbar, click Upload and select a file on your local machine (this tutorial will use mycloudshelltextfile.txt). By default, when you upload a file, it’s saved in your home folder (/home/%USERNAME%), not on your clouddrive.

How do I access Azure cloud shell?
Uploading a File in Azure Cloud Shell

At the bottom-right of the page, you’ll see a confirmation saying the file upload process is complete.

How do I access Azure cloud shell?
Upload Success Confirmation

3. Next, copy the file (mycloudshelltextfile.txt) to your clouddrive with the Copy-Item PowerShell command.

The command below specifies the file’s name to upload (./mycloudshelltextfile.txt) and defines the destination path to /home/<username>/clouddrive. Add the optional Verbose parameter to display a detailed output of the result.

Related:Copy-Item: Copying Files like a Boss in PowerShell

Copy-Item ./mycloudshelltextfile.txt /home/<username>/clouddrive -Verbose

4. Finally, run the Get-ChildItem command to view the contents of your clouddrive (/home/<username>/clouddrive). You’ll notice below that the mycloudshelltextfile.txt file is present on the clouddrive which will now persist over different Cloud Shell sessions.

Related:Get-ChildItem: Listing Files, Registry, and Certificates

Get-ChildItem /home/<username>/clouddrive

How do I access Azure cloud shell?
Viewing Contents Inside the Cloud Drive

Accessing Command Line Tools Available in Cloud Shell

Learning the basics is fun but let’s take this Azure Cloud Shell experience up a notch. Cloud Shell supports a wide variety of tools that are accessible from both PowerShell and Bash. You’ll get to experience some of these tools first hand, so let’s dive in!

Cloning a Git Repository

If you’re a Git fan, then you’re in luck. The Azure Cloud Shell container comes with Git installed by default. Let’s go through one of the basic Git commands (

cd Azure:
3) to clone a repository to your clouddrive.

Maybe you have a favorite GitHub repository you’d like to work on in Cloud Shell. No problem, just run

cd Azure:
4 and provide the repository’s URL. The example below is navigating to the clouddrive first to ensure the cloned repo is available when the current Cloud Shell session is ended.

cd clouddrive
git clone <https://github.com/Nick-Rimmer2016/Terraform.git>

How do I access Azure cloud shell?
Cloning a Git Repository

Now see if the repository was cloned successfully by running the ls -l command.

How do I access Azure cloud shell?
Viewing Cloned Repository

Creating Resource Groups via Azure CLI

One of the handiest tools in Azure Cloud Shell, other than Git, is the Azure Command Line Interface (Azure CLI). Azure CLI lets you manage Azure resources from the command line across multiple platforms—talk about flexibility. As an example, let’s go over how to create a resource group in Azure CLI.

Related:Getting Started With Azure CLI

To create a resource group with the Azure CLI, run the az group create command. When you run the az group command below, you’re creating (create) a –resource-group named TESTGrp in the northeurope region and getting optional –verbose output.

az group create --location northeurope --resource-group TESTGrp --verbose

How do I access Azure cloud shell?
Creating Azure Resource Group

Running Terraform

Last on the list of tools available in Azure Cloud Shell is Terraform, the infrastructure as code automation tool by Hashicorp.

Related:Why is Terraform so Popular for DevOps?.

This tutorial is not about Terraform but you can easily confirm Terraform is available in Azure Cloud Shell by checking the version.

terraform --version

You can see below that Microsoft has not yet updated to the latest version. The current version, 1.0.1, only came out last Jul 26, 2021.

How do I access Azure cloud shell?
Retrieve the version of Terraform being used

Using The File Editor

The Azure Cloud Shell is not just a simple shell to run commands in. You can even edit files in a full-fledged file editor built from the open-source Monaco Editor!

  1. Open the editor by clicking on the curly braces in the title bar, as shown below. You’ll be presented with two panes, on the left-hand side are your files and on the right-hand side the actual editor.

How do I access Azure cloud shell?
File Editor Icon

2. Open a file in the editor by navigating to a file in the left pane and clicking on it. You’ll see the file is then opened in the right-hand pane, as shown below.

You can alternatively open a file directly from the command line by typing code <path to the file to open>.

How do I access Azure cloud shell?
opening a file by clicking on the filename

3. If you’ve made some changes to the file and would like to save it, click on the ellipses shown below by the red arrow and click on Save.

How do I access Azure cloud shell?
Saving a file

4. Once done, close the editor by clicking on the ellipsis on the right-hand corner of the editor, as shown below, then select Close Editor.

How do I access Azure cloud shell?
Close Editor

Alternatively, you could hit Ctrl+Q to quit the editor.

Using the File Editor Command Palette

Just like Visual Studio Code, the built-in Azure Cloud Shell editor has a Command Palette. To access it, click on the ellipses in the upper right corner and click on Command Palette… This action will show you the options available in the command palette for editing your files.

How do I access Azure cloud shell?
Command palette

How do I access Azure cloud shell?
Command palette

Testing Web Applications with the Web Preview

This feature can be great for those times when you need to preview a web application before you actually deploy it into production.

To demonstrate the Web Preview feature, let’s create a web server with Python and see how to view the page it serves with Web Preview.

The following demonstration will cover Web Preview in a Bash shell but the exact same commands can be run in PowerShell also.

1. Start a simple web server with Python by running the below command. This command tells Python to bring up a web server that’s listening on port 9001.

cd Azure:
0

There’s no need to install Python. It comes installed by default!

How do I access Azure cloud shell?
Python http server

2. To view the page that the web server is providing, click on the Web Preview icon and click on Configure.

How do I access Azure cloud shell?
Configure port for web server

3. Now, provide the port that the webserver is listening on (9001 in this case) and click on Open and Browse. This action will render the web page that web server is providing.

How do I access Azure cloud shell?
Add port and then Open and Browse

You should now see a directory listing for the Azure Cloud Shell’s container filesystem.

How do I access Azure cloud shell?
Directory Listing

4. Close the web page and go back to the shell and you’ll notice HTTP GET requests being logged from opening the web page rendered by the http server.

How do I access Azure cloud shell?
get requests

5. Finally, to shut down, the web server, type Ctrl-Z.

Miscellaneous Cloud Shell Actions

Not to forget some of the still useful but smaller features, let’s now cover some of the options you’ll find in the Cloud Shell’s toolbar.

Managing Sessions

If you need to restart or create a new session to bring up a new container in the background, the Cloud Shell toolbar is the way to go.

Note that the Cloud Shell has a timeout of 20 minutes. If you are idle for more than 20 minutes, the Cloud Shell will terminate the session and you will be forced to reconnect.

Restarting the Current Session

As mentioned earlier, Azure Cloud Shell spins up a new container when you start it. If, for some reason, you’d like to start over without closing and reopening your browser, click the restart icon.

Remember to save any of your work before doing a restart, as the container is destroyed and new one created!

How do I access Azure cloud shell?
Restart Icon

Starting a New Session

Maybe you need to start a new session to work on a new project but want to use the environment you’re in. No problem. Click on the new session icon, as shown below, to start a new Cloud Shell session in another web browser tab.

Starting a new session via the toolbar does not create another container in the background. All of your files and state will still be available.

How do I access Azure cloud shell?
Creating a new Cloud Shell session

Changing Font and Font Size

Is the font or font size not up to your liking? Change it by clicking the gear icon, as shown below and selecting the Text size or Font.

How do I access Azure cloud shell?
Settings Icon

How do I access Azure cloud shell?
Courier New, large text size

Integrating Cloud Shell with Visual Studio Code

If you regularly find yourself in the Azure Cloud Shell but are also an avid VS Code user, there’s no need to switch back and forth. Instead, integrate the Cloud Shell right in to VS Code! VS Code is a popular code editor and lets you leverage its features while taking advantage of Azure extensions‘ extensive library for VS Code at the same time.

Let’s now see what it takes to integrate the Cloud Shell in VS Code.

Related:What You Need to Know about Visual Studio Code

1. Open VS Code.

2. Next, install the Azure Account extension by clicking on the extensions icon at the Activity Bar, searching for ‘Azure Account,’ and clicking Install.

How do I access Azure cloud shell?
Installing Azure Accounts Extension

3. Open the Command Palette by clicking on the View menu —> Command Palette. Here you can find the command to initiate an Azure Cloud Shell.

How do I access Azure cloud shell?
Accessing Command Palette in VS Code

4. Now launch Cloud Shell in a PowerShell shell, for example, by clicking on the Azure: Open PowerShell in Cloud Shell in the Command Palette.

You must have to type ‘Azure: open’ to filter the list of available commands.

How do I access Azure cloud shell?
Launching Cloud Shell

5. If you are not signed in through the Azure Account extension, VS Code will prompt you to authenticate. To do so, click on Sign in, and you’ll be taken to a webpage where you’ll sign in with your Azure account.

How do I access Azure cloud shell?
Sign In to Azure

6. In the web browser, click on the account to sign in and enter your password. Once you provide your credentials, VS Code will see this and should be authenticated.

How do I access Azure cloud shell?
Azure Account Authentication

7. Finally, move back to VS Code, and you will see that your VS Code terminal has changed to an active Cloud Shell session. You can now run any command you wish just as if you were in your browser.

How do I access Azure cloud shell?
Active Cloud Session in VS Code Terminal

8. To close the session, select Azure: Sign Out from the Command Palette, as shown in the screenshot below:

How do I access Azure cloud shell?
Azure Sign Out

Conclusion

This article aims to whet your appetite and see what you can achieve with Cloud Shell. And having walked through this tutorial, you now understand what Azure Cloud Shell is. You’ve also learned how to access powerful tools within Cloud Shell to manage your Azure resources.

Now it’s time to leverage those tools to build your projects! Which Azure Cloud Shell feature piqued your interest the most?

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

Explore ATA Guidebooks

More from ATA Learning & Partners

  • How do I access Azure cloud shell?

    Recommended Resources for Training, Information Security, Automation, and more!

  • How do I access Azure cloud shell?

    Get Paid to Write!

    ATA Learning is always seeking instructors of all experience levels. Regardless if you’re a junior admin or system architect, you have something to share. Why not write on a platform with an existing audience and share your knowledge with the world?

  • How do I access Azure cloud shell?

    ATA Learning Guidebooks

    ATA Learning is known for its high-quality written tutorials in the form of blog posts. Support ATA Learning with ATA Guidebook PDF eBooks available offline and with no ads!