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. Show
Enable Azure Cloud BASH shell1. Login to Azure portal. 2. Click on the Cloud shell icon. Top right – > Next to the search bar. (highlighted) Launch Azure Cloud shell3. If you are familiar with bash, select bash shell to launch. Bash Powershell – Azure Cloud Shell4. 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 LanguagesLanguageVersion.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: 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 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 4 – Now successfully created for my cloud shell profile. So, At the top of the following screenshot, you can see the details below: 5 – OK, now see we have a terminal which is very similar to a Linux terminal 6 – To discover all available command run the following “AZ help” command 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?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 ShellNow 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!
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. Starting up of Cloud Shell3. Now, click on Show advanced settings in the dialog box, as shown below. Accessing Advanced Settings Fill in the required fields as explained below and click on Create Storage.
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. Active Cloud Shell SessionSwitching to a Bash Shell Getting Cloud Drive InformationNow 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.
Let’s first inspect the clouddrive by running the PowerShell cmdlet 1, as shown below. You’ll see that running the 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. Getting clouddrive InformationAccessing the Azure Drive to Navigate Azure ResourcesThe 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. Accessing Azure Drive2. 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. Results for dir3. Drill down deeper by changing to the Pay-As-You-Go “folder” and run dir again to view its contents.
In the image below, you’ll see all Azure resources available in your subscription. Viewing Azure Resources
4. Now, navigate to any of your Azure resources by running the command below, replacing <resources> with your preferred resources name.
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. All Resources in AzureAll Resources in Azure Uploading A File To Azure via Cloud ShellYou have a clouddrive ready to store files so let’s now upload some to it and see how that works.
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. Uploading a File in Azure Cloud ShellAt the bottom-right of the page, you’ll see a confirmation saying the file upload process is complete. Upload Success Confirmation3. 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
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 Viewing Contents Inside the Cloud DriveAccessing Command Line Tools Available in Cloud ShellLearning 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 RepositoryIf 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 ( 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 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. Cloning a Git RepositoryNow see if the repository was cloned successfully by running the ls -l command. Viewing Cloned RepositoryCreating Resource Groups via Azure CLIOne 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. Creating Azure Resource GroupRunning TerraformLast 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.
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. Retrieve the version of Terraform being usedUsing The File EditorThe 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!
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. 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. Saving a file4. 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. Close Editor
Using the File Editor Command PaletteJust 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. Command paletteCommand paletteTesting Web Applications with the Web PreviewThis 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.
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. 0Python http server 2. To view the page that the web server is providing, click on the Web Preview icon and click on Configure. Configure port for web server3. 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. Add port and then Open and BrowseYou should now see a directory listing for the Azure Cloud Shell’s container filesystem. Directory Listing4. 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. get requests5. Finally, to shut down, the web server, type Ctrl-Z. Miscellaneous Cloud Shell ActionsNot 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 SessionsIf 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.
Restarting the Current SessionAs 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. Restart Icon Starting a New SessionMaybe 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. Creating a new Cloud Shell session Changing Font and Font SizeIs 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. Settings IconCourier New, large text sizeIntegrating Cloud Shell with Visual Studio CodeIf 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. Installing Azure Accounts Extension3. Open the Command Palette by clicking on the View menu —> Command Palette. Here you can find the command to initiate an Azure Cloud Shell. Accessing Command Palette in VS Code4. Now launch Cloud Shell in a PowerShell shell, for example, by clicking on the Azure: Open PowerShell in Cloud Shell in the Command Palette. 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. Sign In to Azure6. 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. Azure Account Authentication7. 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. Active Cloud Session in VS Code Terminal8. To close the session, select Azure: Sign Out from the Command Palette, as shown in the screenshot below: Azure Sign OutConclusionThis 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 GuidebooksMore from ATA Learning & Partners
|