Bird
Raised Fist0
Azurecloud~5 mins

Creating a VM in Azure Portal - Step-by-Step CLI Walkthrough

Choose your learning style10 modes available
Introduction
Sometimes you need a computer in the cloud to run your apps or store files. Creating a Virtual Machine (VM) in Azure Portal lets you have a ready-to-use computer without buying hardware.
When you want to run a website on a cloud computer without managing physical servers
When you need a test environment to try software without affecting your own computer
When you want to run a database server accessible from anywhere
When you need to run a custom application that requires specific operating system settings
When you want to quickly scale your computing power up or down based on demand
Commands
This command logs you into your Azure account from the command line so you can manage resources like VMs.
Terminal
az login
Expected OutputExpected
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ABCD1234 to authenticate. You have logged in. Now let us find all the subscriptions to which you have access...
This command creates a new VM named 'myVM' in the resource group 'myResourceGroup' using the latest Ubuntu image. It also creates SSH keys for secure login.
Terminal
az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys
Expected OutputExpected
{ "fqdns": "", "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM", "location": "eastus", "name": "myVM", "powerState": "VM running", "privateIpAddress": "10.0.0.4", "publicIpAddress": "52.170.12.34", "resourceGroup": "myResourceGroup", "zones": "" }
→
--resource-group - Specifies the group where the VM will be created
→
--image - Specifies the operating system image for the VM
→
--generate-ssh-keys - Automatically creates SSH keys for secure access
This command shows detailed information about the VM to confirm it is running and to get its IP address.
Terminal
az vm show --resource-group myResourceGroup --name myVM --show-details
Expected OutputExpected
{ "hardwareProfile": { "vmSize": "Standard_DS1_v2" }, "osProfile": { "computerName": "myVM", "adminUsername": "azureuser" }, "networkProfile": { "networkInterfaces": [ { "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic" } ] }, "powerState": "VM running", "publicIps": "52.170.12.34" }
→
--show-details - Displays extra information like power state and public IP
This command connects you securely to your new VM using SSH and the username you set.
Terminal
ssh azureuser@52.170.12.34
Expected OutputExpected
The authenticity of host '52.170.12.34 (52.170.12.34)' can't be established. ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '52.170.12.34' (ECDSA) to the list of known hosts. azureuser@myVM:~$
Key Concept

If you remember nothing else from this pattern, remember: Creating a VM in Azure Portal means choosing a resource group, an OS image, and setting up secure access to have a ready cloud computer.

Common Mistakes
Not creating or specifying a resource group before creating the VM
Azure needs a resource group to organize resources; without it, the VM creation fails.
Create a resource group first using 'az group create --name myResourceGroup --location eastus' or specify an existing one.
Forgetting to generate or provide SSH keys for Linux VMs
Without SSH keys, you cannot securely connect to the VM.
Use the '--generate-ssh-keys' flag or provide your own keys with '--ssh-key-value'.
Trying to SSH before the VM is fully running or before the public IP is assigned
The connection will fail because the VM is not ready or has no reachable IP.
Check VM status and public IP with 'az vm show' before connecting.
Summary
Use 'az vm create' with a resource group, VM name, and OS image to create a VM.
Check VM status and get its public IP with 'az vm show'.
Connect securely to the VM using SSH with the provided username and public IP.

Practice

(1/5)
1. What is the first step when creating a Virtual Machine (VM) in the Azure Portal?
easy
A. Choose the VM name and region
B. Connect to the VM using SSH
C. Select the VM size after creation
D. Install software on the VM

Solution

  1. Step 1: Start VM creation in Azure Portal

    When creating a VM, you first open the Azure Portal and start the 'Create a virtual machine' process.
  2. Step 2: Enter basic details like name and region

    The first required details are the VM's name and the region where it will be hosted.
  3. Final Answer:

    Choose the VM name and region -> Option A
  4. Quick Check:

    First step is naming and region selection [OK]
Hint: Name and region come first when creating a VM [OK]
Common Mistakes:
  • Trying to connect before VM is created
  • Selecting size before naming VM
  • Installing software before VM setup
2. Which option correctly describes the step to select the operating system image when creating a VM in Azure Portal?
easy
A. Skip image selection; Azure picks automatically
B. Choose the image after VM creation
C. Upload your own OS image only
D. Select the image during VM setup under 'Image' section

Solution

  1. Step 1: Locate the 'Image' section in VM creation

    During VM setup, there is a section called 'Image' where you select the OS image.
  2. Step 2: Select a predefined OS image

    You pick from available images like Windows Server or Ubuntu Linux before creating the VM.
  3. Final Answer:

    Select the image during VM setup under 'Image' section -> Option D
  4. Quick Check:

    Image selection happens during setup [OK]
Hint: Pick OS image during VM setup, not after [OK]
Common Mistakes:
  • Thinking image is chosen after VM is created
  • Assuming Azure picks image automatically
  • Believing you must upload your own image
3. After creating a Linux VM in Azure Portal, which method is used to connect to it?
medium
A. Remote Desktop Protocol (RDP)
B. SSH (Secure Shell)
C. FTP (File Transfer Protocol)
D. HTTP (Hypertext Transfer Protocol)

Solution

  1. Step 1: Identify the OS type of the VM

    The VM is Linux-based, which typically uses SSH for secure command-line access.
  2. Step 2: Use SSH to connect

    SSH is the standard protocol to connect securely to Linux VMs remotely.
  3. Final Answer:

    SSH (Secure Shell) -> Option B
  4. Quick Check:

    Linux VM connection uses SSH [OK]
Hint: Linux VMs connect via SSH, Windows via RDP [OK]
Common Mistakes:
  • Trying to use RDP on Linux VM
  • Using FTP or HTTP to connect to VM
  • Confusing protocols for connection
4. You created a Windows VM but cannot connect using Remote Desktop. What is the most likely cause?
medium
A. Network security group (NSG) blocks RDP port 3389
B. The VM size is too small
C. You selected a Linux image by mistake
D. The VM name is invalid

Solution

  1. Step 1: Check network security settings

    Remote Desktop uses port 3389, which must be allowed in the VM's network security group (NSG).
  2. Step 2: Identify blocked port issue

    If NSG blocks port 3389, RDP connections fail even if VM is running.
  3. Final Answer:

    Network security group (NSG) blocks RDP port 3389 -> Option A
  4. Quick Check:

    Blocked RDP port causes connection failure [OK]
Hint: Open port 3389 in NSG for Windows VM RDP [OK]
Common Mistakes:
  • Assuming VM size affects RDP connection
  • Confusing OS image type after creation
  • Thinking VM name affects connectivity
5. You want to create a VM in Azure Portal that can be accessed securely from anywhere. Which combination of settings is best?
hard
A. Use a Linux VM, use password authentication, block all inbound ports
B. Use a Windows VM, use password authentication, open port 3389 to all IPs
C. Use a Linux VM, select SSH key authentication, open port 22 in NSG
D. Use a Windows VM, disable NSG, connect via RDP

Solution

  1. Step 1: Choose secure authentication method

    SSH key authentication is more secure than passwords for Linux VMs.
  2. Step 2: Open only necessary port in NSG

    Opening port 22 for SSH allows secure remote access; avoid opening unnecessary ports.
  3. Step 3: Avoid insecure options

    Opening RDP port 3389 to all IPs or disabling NSG reduces security.
  4. Final Answer:

    Use a Linux VM, select SSH key authentication, open port 22 in NSG -> Option C
  5. Quick Check:

    SSH key + port 22 open = secure access [OK]
Hint: Use SSH keys and open only port 22 for secure Linux VM access [OK]
Common Mistakes:
  • Using password authentication over SSH
  • Opening RDP port to all IPs
  • Disabling NSG for convenience
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard