Day 2 of 5
⏱ ~60 minutes
Azure in 5 Days — Day 2

Virtual Machines

Create a Linux VM, configure inbound ports, connect via SSH, and understand VM sizing and cost.

Creating a VM with CLI

Azure CLI — Create VM
az vm create \
  --resource-group myapp-rg \
  --name my-linux-vm \
  --image Ubuntu2204 \
  --size Standard_B1s \
  --admin-username azureuser \
  --generate-ssh-keys

# Open port 80 for web traffic
az vm open-port --resource-group myapp-rg --name my-linux-vm --port 80
az vm open-port --resource-group myapp-rg --name my-linux-vm --port 443

# Get the public IP
az vm show -d -g myapp-rg -n my-linux-vm --query publicIps -o tsv

# SSH in
ssh azureuser@
Install Nginx on the VM
# Once SSH'd in:
sudo apt update && sudo apt install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
# Visit the public IP in your browser — you should see the Nginx welcome page
Stop/Deallocate when done
# Deallocated = no compute charges (storage still billed)
az vm deallocate --resource-group myapp-rg --name my-linux-vm

# Start again
az vm start --resource-group myapp-rg --name my-linux-vm
⚠️
Stopped (not deallocated) VMs still incur compute charges in Azure. Always use az vm deallocate, not just stop, when you're done for the day.
📝 Day 2 Exercise
Deploy a Web Server on Azure VM
  1. C
  2. r
  3. e
  4. a
  5. t
  6. e
  7. a
  8. B
  9. 1
  10. s
  11. U
  12. b
  13. u
  14. n
  15. t
  16. u
  17. V
  18. M
  19. .
  20. S
  21. S
  22. H
  23. i
  24. n
  25. .
  26. I
  27. n
  28. s
  29. t
  30. a
  31. l
  32. l
  33. N
  34. g
  35. i
  36. n
  37. x
  38. .
  39. R
  40. e
  41. p
  42. l
  43. a
  44. c
  45. e
  46. t
  47. h
  48. e
  49. d
  50. e
  51. f
  52. a
  53. u
  54. l
  55. t
  56. p
  57. a
  58. g
  59. e
  60. w
  61. i
  62. t
  63. h
  64. a
  65. c
  66. u
  67. s
  68. t
  69. o
  70. m
  71. H
  72. T
  73. M
  74. L
  75. f
  76. i
  77. l
  78. e
  79. .
  80. V
  81. e
  82. r
  83. i
  84. f
  85. y
  86. i
  87. t
  88. l
  89. o
  90. a
  91. d
  92. s
  93. v
  94. i
  95. a
  96. t
  97. h
  98. e
  99. p
  100. u
  101. b
  102. l
  103. i
  104. c
  105. I
  106. P
  107. .
  108. D
  109. e
  110. a
  111. l
  112. l
  113. o
  114. c
  115. a
  116. t
  117. e
  118. t
  119. h
  120. e
  121. V
  122. M
  123. w
  124. h
  125. e
  126. n
  127. d
  128. o
  129. n
  130. e
  131. .

Day 2 Summary

  • Standard_B1s is the smallest VM size — cheap for experiments. Production uses larger sizes.
  • --generate-ssh-keys creates a key pair and stores it locally. Use it — don't use passwords.
  • NSG (Network Security Group) controls which ports are open. Default: SSH (22) only.
  • az vm deallocate stops billing for compute. Don't just 'stop' — that still charges.
Finished this lesson?