2 minutes reading time (385 words)

Install Ubuntu on Azure VM (Video Guide)

How to create an Ubuntu VM using the Azure Portal. Create resource group, Virtual Network (VNet) and Network Security Group (NSG). Configure NSG to allow SSH from your IP address and connect to the Ubuntu VM using SSH.

Install Ubuntu on Azure VM (Video Guide)

Create Resource Group using PowerShell

$RGName = "test-ubuntu-rg"
$Location = "UK West"

New-AzResourceGroup -Name $RGName -Location $Location 

Create Virtual Network (VNet) using PowerShell

$RGName = "test-ubuntu-rg"
$Location = "UK West"
$VNetName = "test-ubuntu-vnet"
$VNetAddress = ""
$SubnetName = "subnet01"
$SNetAddress = ""

$virtualNetwork = New-AzVirtualNetwork `
-ResourceGroupName $RGName `
-Location $Location `
-Name $VNetName `
-AddressPrefix $VNetAddress 
$subnetConfig = Add-AzVirtualNetworkSubnetConfig `
-Name $SubnetName `
-AddressPrefix $SNetAddress `
-VirtualNetwork $virtualNetwork

$virtualNetwork | Set-AzVirtualNetwork 

Create Network Security Group (NSG) using PowerShell

$RGName = "test-ubuntu-rg"
$NSGName = "test-ubuntu-vnet-nsg"
$Location = "UK West"

New-AzNetworkSecurityGroup `
   -Name $NSGName `
   -ResourceGroupName $RGName `
   -Location $Location  

Attach NSG to subnet using PowerShell

$RGName = "test-ubuntu-rg"
$VNetName = "test-ubuntu-vnet"
$SubnetName = "subnet01"
$SNetAddress = ""
$NSGName = "test-ubuntu-vnet-nsg"

$virtualNetwork = Get-AzVirtualNetwork -Name $VNetName -ResourceGroupName $RGName
$networkSecurityGroup = Get-AzNetworkSecurityGroup -Name $NSGName -ResourceGroupName $RGName

Set-AzVirtualNetworkSubnetConfig `
-Name $SubnetName `
-VirtualNetwork $virtualNetwork `
-AddressPrefix $SNetAddress `
-NetworkSecurityGroup $networkSecurityGroup 

Set-AzVirtualNetwork -VirtualNetwork $virtualNetwork 

Configure NSG to allow SSH

Configure NSG to allow SSH from your IP address

Create Ubuntu VM using Azure Portal

Resource Group: test-ubuntu-rg
Virtual machine name: test-ubuntu

Region: UK West
Security type: Standard
Image: Ubuntu Server 20.04 LTS
Size: B2s

Authentication type: SSH public key
Username: ubuntuadmin
SSH public key source: Generate new key pair
Key pair name: test-ubuntu_key
Public inbound ports: SSH 22

OS disk type: Standard SSD

Virtual network: test-ubuntu-vnet
Subnet: subnet01
Public IP: new
NIC network security group: None

Connect to Ubuntu VM using SSH

Copy the private key .pem file to `C:\Users\Documents\ssh
Get the VM public IP from the Azure portal

Open Windows Terminal

ssh -i C:\Users\TechLabs\Documents\ssh\test-ubuntu_key.pem ubuntuadmin@ 


Quickstart: Use Azure PowerShell to create a virtual network

Create, change, or delete a network security group

Azure PowerShell New-AzNetworkSecurityGroup

Related Posts



No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Saturday, 23 September 2023
You can help support this website by buying me a coffee!
Buy Me A Coffee