Hakia LogoHAKIA.com

Step-by-Step: Setting Up Your First Azure Virtual Machine

Author

Taylor

Date Published

Categories

Conceptual image of Azure cloud interface showing virtual machine configuration or deployment.

Setting Up Your First Azure Virtual Machine: A Step-by-Step Guide

Cloud computing offers incredible flexibility, and one of the core components is the virtual machine (VM). Microsoft Azure provides a powerful platform for creating and managing VMs in the cloud. Think of an Azure VM as your own computer—with an operating system, storage, and networking capabilities—but running on Microsoft's hardware in their data centers instead of physically in front of you. This guide will walk you through the process of setting up your very first Azure VM, explaining each step along the way.

Why use an Azure VM? They are highly scalable, meaning you can easily adjust their computing power (CPU, RAM) and storage as your needs change. You only pay for what you use, making them cost-effective for various tasks, from hosting websites and applications to running development environments or performing data analysis. Let's get started.

What You'll Need Before You Start

Before creating your VM, ensure you have the following:

  • An Azure Account: You need an active Azure subscription. If you're new to Azure, Microsoft often offers a free trial account with credits to get you started.
  • Basic Understanding: While this guide is step-by-step, having a general understanding of computer concepts (like operating systems, IP addresses) is helpful. Building foundational tech knowledge from various online information hubs can make the process smoother.

Step 1: Accessing the Azure Portal

The Azure portal is the web-based interface where you manage all your Azure resources. Open your web browser and go to portal.azure.com. Log in using the credentials associated with your Azure account. Once logged in, you'll see the Azure dashboard.

Step 2: Starting the VM Creation Process

In the Azure portal, the easiest way to find services is using the search bar at the top.

  1. Type "virtual machines" into the search bar.
  2. Under the "Services" category in the search results, select "Virtual machines".
  3. On the "Virtual machines" page, click the "+ Create" button and then select "Azure virtual machine".

This opens the "Create a virtual machine" page, where you'll configure all the settings for your new VM.

Step 3: Configuring Basic Details

The first tab, "Basics", covers the fundamental settings:

  • Subscription: Select the Azure subscription you want to use (most users starting out will only have one).
  • Resource Group: A resource group is like a container that holds related Azure resources. For your first VM, it's easiest to click "Create new" and give it a meaningful name (e.g., "MyFirstVMResources"). Grouping resources makes them easier to manage and delete later.
  • Virtual machine name: Choose a unique name for your VM (e.g., "MyTestVM"). This name will be used to identify the VM within Azure.
  • Region: Select the Azure data center location where your VM will be hosted. Choose a region geographically close to you or your users for better performance (lower latency).
  • Availability options: For your first VM, you can usually leave the default ("No infrastructure redundancy required"). More advanced options like Availability Zones or Sets provide higher uptime guarantees by distributing VM instances.
  • Image: This is the operating system template for your VM. You can choose various Windows Server versions or Linux distributions (like Ubuntu, CentOS, etc.). For example, you might select "Windows Server 2022 Datacenter" or "Ubuntu Server 22.04 LTS". Microsoft provides detailed guides if you specifically want to create a Windows virtual machine or create a Linux virtual machine in the Azure portal.

Step 4: Choosing the VM Size

The "Size" setting determines the compute resources (CPU cores, RAM) and associated cost of your VM. Azure offers a vast range of VM sizes optimized for different workloads (general purpose, compute-intensive, memory-intensive, etc.).

For a first VM or simple testing, a smaller, general-purpose size (like one from the B-series or D-series) is usually sufficient and cost-effective. You can click "See all sizes" to browse options and their estimated monthly costs. Select a size that fits your initial needs; you can always resize the VM later if required.

Step 5: Setting Up the Administrator Account

You need credentials to log in to your VM once it's created. The options depend on the OS image you selected:

  • Windows VMs: You'll typically set a Username and Password. Choose a strong password (Azure enforces complexity requirements, usually at least 12 characters with uppercase, lowercase, numbers, and symbols). Remember these credentials!
  • Linux VMs: The more secure and common method is using an SSH public key. Select "SSH public key" as the Authentication type. You can provide your own existing public key, or choose "Generate new key pair". If you generate a new pair, enter a Key pair name (e.g., "myVMKey"). Azure will create the key pair, and you'll download the private key file (.pem) later during the creation process. You'll also need to provide a Username (e.g., "azureuser"). Using a password is also an option for Linux, but key-based authentication is generally recommended.

Step 6: Configuring Inbound Port Rules (Firewall)

Under "Inbound port rules", you control what network traffic is allowed to reach your VM from the internet. This is handled by a Network Security Group (NSG), which acts like a basic firewall.

Select "Allow selected ports" under "Public inbound ports". Then, choose the ports you need open:

  • For Windows: Select RDP (3389). This allows you to connect using Remote Desktop.
  • For Linux: Select SSH (22). This allows you to connect using Secure Shell.
  • For Web Server: If you plan to host a website, also select HTTP (80) and possibly HTTPS (443).

It's best practice to only open the ports you absolutely need.

Step 7: Configuring Disks

Navigate to the "Disks" tab. Here you configure the storage for your VM.

OS disk type: This determines the performance of the disk where the operating system is installed. Options typically include:

  • Standard HDD: Lowest cost, suitable for non-intensive workloads or backups.
  • Standard SSD: Good balance of performance and cost, suitable for most general-purpose VMs, web servers, and development environments.
  • Premium SSD: High performance, low latency, best for production workloads and databases.

For learning purposes, Standard SSD is often a good starting point. You can also attach additional "Data disks" if you need more storage space separate from the OS disk, but this isn't necessary for a basic setup.

Step 8: Configuring Networking

Go to the "Networking" tab. Azure usually creates reasonable defaults here, but it's good to understand the basics:

  • Virtual network (VNet): This is your private network space in Azure. Your VM will reside within a VNet. Azure typically creates a new one for you if you don't select an existing one.
  • Subnet: A VNet is divided into smaller ranges called subnets. Your VM gets its private IP address from the subnet it's placed in. Again, Azure usually creates a default subnet.
  • Public IP: To connect to your VM from the internet (e.g., via RDP or SSH), it needs a Public IP address. Azure creates a new one by default. You can choose to have no public IP if the VM only needs to communicate within the private network.
  • NIC network security group: This should already reflect the inbound port rules you configured on the Basics tab (like allowing RDP or SSH). Selecting "Basic" is fine for starting.

For a simple first VM, the default networking settings created by Azure are usually adequate. More complex setups might involve custom VNet designs and subnet configurations, as detailed in some online guides about creating VMs, but stick with the defaults for now.

Step 9: Management and Monitoring Options (Optional)

The "Management" and subsequent tabs offer additional configuration options. For a first VM, you might consider:

  • Boot diagnostics: Enabled by default, this captures console output and screenshots, which can be helpful if the VM fails to boot.
  • Auto-shutdown: Found under the "Management" tab (or configured later). This is very useful for test/dev VMs to save costs. You can set a specific time each day for the VM to automatically shut down, ensuring you don't pay for compute time when you aren't using it.

You can skip most other options under Management, Monitoring, and Advanced for your first VM.

Step 10: Review and Create

Click the "Review + create" button at the bottom. Azure will validate your configuration settings. If any required fields are missing or there are configuration errors, it will highlight them.

Once validation passes, carefully review the summary page. Check the VM name, size, region, OS image, networking ports, and estimated cost. Ensure everything looks correct.

Step 11: Deploy the Virtual Machine

If everything on the review page is accurate, click the "Create" button.

If you chose to generate a new SSH key pair for a Linux VM, a prompt will appear: "Generate new key pair". Click "Download private key and create resource". Your browser will download the private key file (e.g., "myVMKey.pem"). Save this file in a secure location on your computer. You will need it to connect to your Linux VM. Do not lose this file, as Azure does not keep a copy of the private key.

Azure will now start provisioning the resources (the VM itself, network interface, public IP, disk, etc.). This process usually takes a few minutes. You can monitor the deployment progress on the portal screen. Once completed, you'll see a message like "Your deployment is complete". Click the "Go to resource" button to view your newly created VM's overview page.

Step 12: Connecting to Your VM

Now that your VM is running, you need to connect to it. The method depends on the operating system:

Connecting to a Windows VM (using RDP):

  1. On the VM's overview page in the Azure portal, find the "Public IP address" and copy it.
  2. Alternatively, click the "Connect" button at the top and select "RDP".
  3. On the "Connect with RDP" tab, click "Download RDP File".
  4. Open the downloaded .rdp file. Your computer's Remote Desktop Connection client will launch.
  5. Click "Connect". You might see a warning about the publisher; click "Connect" again.
  6. When prompted for credentials, select "More choices" and then "Use a different account".
  7. Enter the username you created (e.g., localhost\your_username or just your_username) and the password you set during VM creation. Click OK.
  8. You might see a certificate warning; click "Yes" or "Continue".
  9. You should now see the Windows desktop of your Azure VM.

Connecting to a Linux VM (using SSH):

  1. On the VM's overview page in the Azure portal, find the "Public IP address" and copy it.
  2. Open a terminal or command prompt on your local computer. (On Windows, you can use PowerShell, Command Prompt, or an SSH client like PuTTY. On macOS or Linux, use the built-in Terminal).
  3. If you're using the downloaded .pem key file on Linux or macOS, you might need to restrict its permissions first. Navigate to the directory where you saved the .pem file and run: chmod 400 your_key_file.pem
  4. Use the SSH command to connect. Replace /path/to/your_key_file.pem with the actual path to your key file, your_username with the admin username you created, and your_vm_public_ip with the copied public IP address:ssh -i /path/to/your_key_file.pem your_username@your_vm_public_ip
  5. The first time you connect, you may be asked to confirm the host's authenticity. Type "yes" and press Enter.
  6. You should now be logged into the command line of your Linux VM.

Step 13: Quick Test (Optional - Install a Web Server)

To verify your VM is working and accessible (if you opened port 80), you can install a simple web server.

  • On Windows: Connect via RDP, open PowerShell (as Administrator), and run: Install-WindowsFeature -name Web-Server -IncludeManagementTools
  • On Linux (Ubuntu): Connect via SSH and run: sudo apt update && sudo apt install -y nginx

After installation, open a web browser on your local computer and navigate to http://your_vm_public_ip. You should see the default welcome page for IIS (Windows) or Nginx (Linux).

Step 14: Cleaning Up Resources

Azure resources incur costs while they are running or provisioned. If you created this VM just for practice or testing, it's crucial to delete the resources when you're finished to avoid ongoing charges.

The easiest way to clean up is to delete the entire Resource Group you created earlier. This will delete the VM and all its associated resources (disk, network interface, public IP, etc.).

  1. Go back to the Azure portal.
  2. Search for "Resource groups" and select it.
  3. Find the resource group you created (e.g., "MyFirstVMResources") and click on its name.
  4. On the resource group's overview page, click the "Delete resource group" button.
  5. You'll be asked to type the resource group's name to confirm the deletion. Do this carefully and then click "Delete".

Alternatively, if you want to keep the VM but stop incurring compute costs temporarily, you can "Stop" the VM from its overview page. Remember that stopped (deallocated) VMs still incur charges for their storage disks. Using the Auto-shutdown feature mentioned earlier is also a good way to manage costs for non-critical VMs. Properly managing your cloud platform assets is essential for cost optimization.

Your First Azure VM

Congratulations! You have successfully created, configured, connected to, and hopefully tested your first Azure Virtual Machine. While this guide covered the basics using the Azure portal, Azure offers many other ways to manage VMs (like Azure CLI, PowerShell, ARM templates) and many more advanced configuration options. However, understanding this fundamental process provides a solid base for exploring further possibilities with Azure VMs.

Sources

https://learn.microsoft.com/en-us/azure/virtual-machines/windows/quick-create-portal
https://medium.com/@srijaanaparthy/step-by-step-guide-creating-a-virtual-machine-in-azure-from-scratch-fbacccc57635
https://learn.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-portal

Abstract visualization representing Microsoft Azure's cloud computing platform and global network infrastructure.
Azure

Learn what Microsoft Azure is, a leading cloud computing platform offering over 200 services. Understand how Azure works through virtualization and its global data center network.

Small business owner considering moving IT infrastructure to the Microsoft Azure cloud platform.
Azure

Considering moving your small business IT to Microsoft Azure? This article explores the key benefits, potential drawbacks, and crucial factors to help you decide if Azure is the right fit.