Creating a Linux VM using Azure CLI

30 minutes
  • 2 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we play the part of a Cloud Engineer who is tasked with using the Azure CLI to provision a Linux-based virtual machine running Nginx. This VM is intended for our web development team’s newest project. In this hands-on lab, we cover Azure CLI syntax, Azure CLI help/parameters, and Network Security Groups.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Virtual Machine

Create a Virtual Machine Using Azure CLI and the Following Settings:

  • Resource Group: (Existing resource group)
  • Name: LabVM
  • Image: UbuntuLTS
  • Admin Username: azureuser
  • Authentication Method: Generate SSH Keys

Note: The resource group has already been created for you.

  1. Login to the Azure Portal using the credentials provided in this hands-on lab.
  2. Navigate to the Cloud Shell, using the >_ icon in the toolbar on the top-right side of the screen.
  3. Ensure you are using PowerShell for Azure Cloud Shell.
  4. Click Show advanced settings.
  5. Use the existing Resource Group.
  6. Choose the Cloud Shell Region that matches the location of your lab provided Resource Group.
  7. Under the Storage account section select Use existing.
  8. Under the File share section select Create new and type in cloudshell.
  9. Select Attach storage.
  10. Once Cloud Shell has opened, identify the existing Resource Group using az group list.
  11. Copy the value of the name: field. This is the Resource Group name.
  12. Set the Resource Group variable by typing $rg = "<insert-resource-group-name>" and press Enter.
  13. Set the virtual machine’s name by creating its variable with $vm = "kaldiVM".
  14. Deploy a virtual machine (VM) by typing:
    az vm create -g $rg -n $vm --image "UbuntuLTS" --admin-username "azureuser" --generate-ssh-keys
  15. After the VM is created copy the publicIPAddress for later use.
Open Port 80 On the VM for Web Traffic

Open Port 80 on VM using Azure CLI

  1. Open port 80 on the VM we created:
    az vm open-port -g $rg -n $vm --port 80

    1. Install Nginx by first logging into the server. Don’t forget to accept the fingerprint:
      ssh azureuser@<PubliIP.OF.VM>
    2. Update the Ubuntu VM:
      sudo apt update -y
    3. Install Ngnix:
      sudo apt-get install nginx -y
    4. Navigate to the web browser and paste in the VM’s IP address. If successful, the default "Welcome to Nginix!" page appears.

Additional Resources

Throughout this lab, we use the Azure Cloud Shell, so Azure CLI configuration is not necessary on your local device. The only tool necessary for this lab is your choice of browser.

Please, go ahead and log in to the live Azure hands-on lab environment by using the credentials provided and the Open Azure Portal button.

NOTE: Pay special attention to the region for the provisioned storage account. This information will be needed to properly configure the Cloud Shell. All resources provisioned as part of this hands-on lab will be located in this region.

The following information will help you throughout this hands-on lab:

  • This hands-on lab uses the Cloud Shell within the Azure Portal, but you may also use Azure CLI if you have it installed on your computer.

  • Once you are familiar with the process, consider completing the lab using the steps first and then try using the videos to verify your solution (the videos contain the complete lab solution).

  • You can expand the objectives to see more information on the tasks this lab undertakes.

  • If you'd like to view the diagram as a visual aid, you can access it by using the Diagram button on the upper-right-hand side of this hands-on lab.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?