How to Create Your First Virtual Machine on Microsoft Azure & Master Complete Troubleshooting

End-to-End Visual Guide: Resource Groups, Sizing, Network Security Groups (NSGs), SSH Connectivity & Step-by-Step Fixes if VM is Not Working

⏱️ 16 Min Read 🏷️ Azure Virtual Machines & Troubleshooting ⚡ Level: Beginner to Pro

Microsoft Azure Virtual Machines (VMs) offer on-demand, scalable cloud computing resources with full administrative control over the guest OS. Whether running enterprise Linux distributions, Windows Servers, or Kubernetes worker nodes, knowing how to properly provision and troubleshoot Azure VMs is an indispensable DevOps skill.

In this guide, you will learn how to create your first Azure VM from scratch, configure Network Security Groups (NSGs) with priority rules, connect seamlessly, and diagnose exactly what to do if your VM is unresponsive, failed, or rejecting connections.

📚 Key Takeaways

  • Creating an Azure Resource Group and provisioning an Ubuntu Linux VM.
  • Selecting cost-effective sizes like Standard_B1s or Standard_B2s.
  • Configuring Network Security Groups (NSGs) and understanding rule priority (100–4096).
  • Diagnosing failed VMs using Boot Diagnostics, Serial Console, Effective Routes & VM Redeployment.

1. Prerequisites

  • An active Microsoft Azure Account ($200 credit for new accounts plus 12 months of popular free services).
  • Access to the Azure Portal (portal.azure.com).
  • An active Azure Subscription (Free Trial or Pay-As-You-Go).

2. Step-by-Step: Creating Your First Azure VM

1 Navigate to Virtual Machines & Click "+ Create"

  1. Log in to portal.azure.com.
  2. In the search bar, type Virtual machines and select it.
  3. Click the blue + Create button and choose Azure virtual machine from the dropdown.
Azure Portal Virtual Machines - Create Azure Virtual Machine

Figure 1: Azure Portal — Navigating to Virtual Machines and clicking '+ Create > Azure virtual machine'.

2 Configure Basics Tab (Resource Group, Name & Size)

  1. Subscription: Select your active subscription (e.g. Pay-As-You-Go).
  2. Resource group: Click Create new and enter rg-devops-training.
  3. Virtual machine name: Enter vm-devops-web-01.
  4. Region: Select (US) East US or a datacenter closest to you.
  5. Image: Select Ubuntu Server 22.04 LTS - x64 Gen2.
  6. Size: Choose Standard_B1s (1 vcpu, 1 GiB memory)Free Tier eligible.
  7. Administrator account: Choose SSH public key and username azureuser.
Azure VM Creation Basics Tab Configuration

Figure 2: Setting Resource Group 'rg-devops-training', VM Name, Ubuntu 22.04 LTS Image, and Standard_B1s Size.

3. Configuring Network Security Groups (NSGs)

A Network Security Group (NSG) contains security rules that allow or deny network traffic to your Azure Virtual Machine. In Azure, NSG rules are evaluated in order of priority from lowest numerical number (100) to highest (4096).

Azure Network Security Group Inbound Security Rules

Figure 3: Azure Network Security Group (NSG) — Inbound security rules configured for SSH (Port 22), HTTP (Port 80), and HTTPS (Port 443).

Priority Name Port Protocol Source Action
300 SSH 22 TCP Any / My IP Allow
320 HTTP 80 TCP Any Allow
340 HTTPS 443 TCP Any Allow
65000 AllowVnetInBound Any Any VirtualNetwork Allow (Default)
65500 DenyAllInBound Any Any Any Deny (Default)

4. Launching and Connecting to Your Azure VM

  1. Click Review + create at the bottom, then click Create.
  2. Download the generated private key file (vm-devops-web-01_key.pem).
  3. Once deployment finishes, click Go to resource to view the VM Overview blade.
Azure Virtual Machine Overview and Public IP

Figure 4: Azure VM Overview blade displaying Public IP address and Status: Running.

Connect via Terminal SSH

# Set correct key permissions
chmod 400 vm-devops-web-01_key.pem

# Connect using SSH
ssh -i vm-devops-web-01_key.pem azureuser@<YOUR-AZURE-PUBLIC-IP>
Connecting to Azure VM via SSH Terminal

Figure 5: Successful SSH connection to the Azure Virtual Machine.

5. 🚨 Master Troubleshooting: What To Do If Your Azure VM Is Not Working

If you cannot connect via SSH or your web server is unreachable, follow this proven troubleshooting flowchart:

🛑 Check 1: Verify VM Power State & Provisioning Status

Go to your VM Overview blade. Check the Status:

  • Stopped (Deallocated): The VM is powered off and releasing compute resources. Click Start at the top bar.
  • Updating / Creating: Wait 1–2 minutes for provisioning to complete.
  • Failed: The VM failed during startup. Click Activity log on the left pane to view the exact error code.

🔍 Check 2: Inspect Boot Diagnostics & Screen Capture

When an OS crashes or is stuck in a kernel panic, standard networking goes down. Azure provides Boot Diagnostics to view an out-of-band screenshot of the virtual monitor without needing network access!

  1. In the VM left menu, scroll down to Help > Boot diagnostics.
  2. Click the Screenshot tab to see the live video output.
  3. If you see a GRUB prompt, kernel panic, or filesystem repair (fsck) prompt, the issue is within the OS filesystem rather than the Azure network.

📟 Check 3: Execute Run Command or Serial Console

If SSH is blocked, use Azure's Run Command or Serial Console to execute bash commands directly on the VM via the Azure Agent:

Azure Run Command for Troubleshooting and Diagnostics

Figure 6: Using Azure Run Command to troubleshoot and restart SSH services remotely without network access.

# Restart SSH service remotely via Run Command
sudo systemctl restart ssh
sudo ufw allow 22/tcp

🛡️ Check 4: Verify NSG Inbound & Effective Security Rules

A higher priority Deny rule may be silently blocking your connections:

  1. Go to Networking in your VM blade.
  2. Verify there is an Inbound Rule for Port 22 (SSH) with Action: Allow.
  3. Check Priority: Ensure no Deny rule with a lower numerical priority (e.g. 100) precedes your Allow rule (e.g. 300).
  4. Click Effective security rules to see the final combined evaluation across Subnet and NIC level firewalls.

🔑 Check 5: Reset SSH Configuration & Public Key

If SSH keys were lost or corrupted, Azure provides a 1-click built-in repair tool:

  1. In the VM left menu, go to Help > Reset password.
  2. Select Reset SSH public key (or Reset configuration only).
  3. Enter your username (azureuser), paste a newly generated SSH public key, and click Update. Azure VM Agent will repair ~/.ssh/authorized_keys and restart the SSH service.

🔄 Check 6: Redeploy the VM to a Fresh Physical Host

If the physical hardware blade in the Azure data center is experiencing underlying hypervisor degradation:

  1. In the VM left menu, scroll down to Help > Redeploy + reapply.
  2. Click Redeploy. Azure will migrate your virtual machine to an entirely new, healthy physical server in the datacenter. (All persistent data on your OS disk is preserved!).

6. Cost Optimization: Auto-Shutdown & Resource Cleanup

⏰ Configure Auto-Shutdown

Never leave a VM running accidentally overnight:

  • In the VM left menu, under Operations, select Auto-shutdown.
  • Enable it, set your timezone, and set scheduled shutdown to 7:00 PM daily with an email notification.
  • When deleting test labs, delete the entire Resource Group (rg-devops-training) to instantly wipe the VM, disk, public IP, and NSG simultaneously.

🎉 Azure Cloud Engineer Level Unlocked!

You now possess end-to-end expertise in provisioning Azure Virtual Machines, tuning Network Security Groups, and executing advanced recovery diagnostics with Boot Diagnostics, Serial Console, and Host Redeployment.