Skip to content

Latest commit

 

History

History
128 lines (97 loc) · 3.54 KB

Instructions.md

File metadata and controls

128 lines (97 loc) · 3.54 KB

Lab: Linux-VM

This Lab is from Microsoft Docs.

Scenario

  • List available Linux VM images from Azure Marketplace.
  • Create VM.
  • Connect to VM via SSH.
  • Install Web server nginx.

Links

Lab Instructions

Start Cloud Shell (Bash)

az account list -o table

Set Variables

Location="westeurope"
RGroup="SinsheimRG"
VM_Name="Web3"
VM_AdminName="paul"
VM_Image="Canonical:UbuntuServer:18.04-LTS:latest"

Create Resource Group

az group create --name $RGroup --location $Location

az group list -o table

List most popular Marketplace images

Syntax: List the VM/VMSS images available in the Azure Marketplace

az vm image list -o table

List Linux Marketplace images

az vm image list-publishers --location $Location -o table
#  publisher --> Canonical

az vm image list-offers --publisher Canonical --location $Location -o table
#  offer --> UbuntuServer

az vm image list-skus --publisher Canonical --offer UbuntuServer --location $Location -o table
#  sku --> 18.04-LTS

az vm image list --publisher Canonical --offer UbuntuServer --sku 18.04-LTS --all --location $Location -o table
#  version --> latest

VM_Image="Canonical:UbuntuServer:18.04-LTS:latest"
az vm image show --urn $VM_Image --location $Location

No SSH keys available

ls -l ~/.ssh

Create VM

Syntax: Create an Azure Virtual Machine

az vm create --name $VM_Name --image $VM_Image --admin-username $VM_AdminName --resource-group $RGroup --generate-ssh-keys
az vm list --resource-group $RGroup \
           --query "[].{\
                        name:name,\
                        location:location,\
                        resourceGroup:storageProfile.osDisk.managedDisk.resourceGroup,\
                        osType:storageProfile.osDisk.osType,\
                        size:hardwareProfile.vmSize,\
                        provisioningState:provisioningState\
                       }"\
           -o table

az vm show --name $VM_Name --resource-group $RGroup --show-details -o table
az vm show --name $VM_Name --resource-group $RGroup --show-details \
           --query "{name:name,\
                     location:location,\
                     powerState:powerState,\
                     publicIps:publicIps,\
                     privateIps:privateIps,\
                     adminUsername:osProfile.adminUsername\
                    }"\
           -o table

Note the public IP address

VM_PublicIp=$(az vm show --name $VM_Name --resource-group $RGroup --show-details \
                         --query "[publicIps]"\
                         -o tsv)

echo $VM_PublicIp

Inspect SSH keys

ls -l ~/.ssh
cat ~/.ssh/id_rsa.pub

Inspect the NSG

Syntax: List network security groups

az network nsg list --resource-group $RGroup -o table

Open port 80 for web traffic

Syntax: Open a VM to inbound traffic on specified ports

az vm open-port --name $VM_Name --port 80 --resource-group $RGroup