Linux VM vs Windows VM
| Factor | Linux VM | Windows VM |
|---|---|---|
| OS licence cost | Free — no licence fee | Included in VM price (~40% premium) |
| Connection method | SSH (port 22) | RDP (port 3389) |
| Authentication | SSH keys (recommended) or password | Password |
| Typical use | Web servers, containers, cloud-native | Legacy apps, .NET, SQL Server, AD |
| VM name limit | 64 characters | 15 characters |
| Cost (B2s example) | ~₹2,200/month | ~₹4,000/month |
Choosing a Linux Distribution
Azure supports many Linux distributions. Here are the most popular:
| Distribution | Best For | Notes |
|---|---|---|
| Ubuntu Server 22.04 LTS | General use, developers | Most popular, huge community, great documentation |
| Ubuntu Server 20.04 LTS | Stable workloads | Older LTS, still widely used |
| Red Hat Enterprise Linux (RHEL) | Enterprise, regulated industries | Paid licence, enterprise support |
| CentOS Stream | RHEL-compatible workloads | Free, upstream of RHEL |
| Debian | Stable, minimal footprint | Rock-solid stability |
| SUSE Linux Enterprise | SAP workloads | Certified for SAP HANA on Azure |
SSH Keys — The Right Way to Authenticate
SSH keys are a more secure alternative to passwords. Instead of typing a password every time you connect, you use a pair of cryptographic keys:
- Private key — Stays on your local machine. Never share this.
- Public key — Goes on the VM. Azure installs this automatically during VM creation.
When you connect, SSH uses your private key to prove your identity — no password needed, and much harder to brute-force than a password.
Generate an SSH Key Pair
# Works on Windows (PowerShell), macOS, and Linux
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"
# When prompted for file location, press Enter for default:
# Linux/Mac: ~/.ssh/id_rsa
# Windows: C:\Users\YourName\.ssh\id_rsa
# When prompted for passphrase:
# Enter a passphrase for extra security (recommended)
# Or press Enter for no passphrase (convenient but less secure)
This creates two files:
id_rsa— Your private key (keep this safe!)id_rsa.pub— Your public key (this goes to Azure)
id_rsa) is like a master password. Never share it, never upload it, never put it in a repository. If it's compromised, anyone can access any server where your public key is installed.
Create VM via Azure Portal
The process is almost identical to creating a Windows VM. Key differences:
Image
Search for Ubuntu Server 22.04 LTS in the image selector.
Authentication Type
Select SSH public key (recommended over password):
- Username — e.g.,
azureuser - SSH public key source — Choose "Use existing public key"
- SSH public key — Paste the contents of your
id_rsa.pubfile
# Linux/Mac
cat ~/.ssh/id_rsa.pub
# Windows PowerShell
Get-Content ~/.ssh/id_rsa.pub
Inbound Port Rules
Select SSH (22) to allow SSH connections.
Create via Azure CLI (Fastest Method)
The CLI method is significantly faster than the portal. Azure CLI can auto-generate SSH keys if you don't have one:
# Create resource group
az group create \
--name rg-linux-vm-demo \
--location centralindia
# Create Ubuntu VM with auto-generated SSH keys
# Keys saved to ~/.ssh/id_rsa automatically
az vm create \
--resource-group rg-linux-vm-demo \
--name vm-ubuntu-demo \
--image Ubuntu2204 \
--size Standard_B2s \
--admin-username azureuser \
--generate-ssh-keys \
--location centralindia \
--public-ip-sku Standard
# Open SSH port 22
az vm open-port \
--resource-group rg-linux-vm-demo \
--name vm-ubuntu-demo \
--port 22
~/.ssh/id_rsa. The public key is installed on the VM. The private key stays on your machine. This is the quickest way to get started.
az vm show \
--resource-group rg-linux-vm-demo \
--name vm-ubuntu-demo \
--show-details \
--query publicIps \
--output tsv
Connecting via SSH
Once you have the VM's public IP address:
ssh azureuser@<YOUR-VM-PUBLIC-IP>
# Example:
ssh azureuser@4.188.23.45
# If your key is not at the default location:
ssh -i ~/.ssh/id_rsa azureuser@4.188.23.45
The first time you connect, SSH will ask you to verify the host fingerprint:
The authenticity of host '4.188.23.45' can't be established.
ED25519 key fingerprint is SHA256:abc123...
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Type yes and press Enter. You're now connected to your Linux VM running in Azure!
First Commands After Login
Once connected, here are the first commands to run on a new Ubuntu VM:
# Update package lists and upgrade all packages
sudo apt update && sudo apt upgrade -y
# Check OS version
lsb_release -a
# Check CPU and memory
nproc # Number of CPUs
free -h # Memory usage
df -h # Disk usage
# Install useful tools
sudo apt install -y curl wget git unzip htop
# Check if the VM can reach the internet
curl https://api.ipify.org
Cleaning Up
az group delete \
--name rg-linux-vm-demo \
--yes \
--no-wait