This Lab is from Microsoft Docs.
- List available Linux VM images from Azure Marketplace.
- Create VM.
- Connect to VM via SSH.
- Install Web server nginx.
az account list -o table
Location="westeurope"
RGroup="SinsheimRG"
VM_Name="Web3"
VM_AdminName="paul"
VM_Image="Canonical:UbuntuServer:18.04-LTS:latest"
az group create --name $RGroup --location $Location
az group list -o table
Syntax: List the VM/VMSS images available in the Azure Marketplace
az vm image list -o table
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
ls -l ~/.ssh
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
VM_PublicIp=$(az vm show --name $VM_Name --resource-group $RGroup --show-details \
--query "[publicIps]"\
-o tsv)
echo $VM_PublicIp
ls -l ~/.ssh
cat ~/.ssh/id_rsa.pub
Syntax: List network security groups
az network nsg list --resource-group $RGroup -o table
Syntax: Open a VM to inbound traffic on specified ports
az vm open-port --name $VM_Name --port 80 --resource-group $RGroup