How To Set Up an Azure Virtual Machine – A Detailed Guide

An Azure Virtual Machine is a cloud-based computing resource that runs on Microsoft’s Azure infrastructure. It gives you the flexibility of a full operating system environment without the cost and maintenance of physical hardware. You can run Windows or Linux, install software, configure networks, and manage storage just like you would on a real server sitting in a data center.

Azure VMs are used across a huge range of scenarios. Developers use them to test applications in isolated environments. Businesses use them to host websites, run databases, and support remote workforces. IT teams use them to extend on-premises infrastructure into the cloud without a full migration. The flexibility and scalability of Azure VMs make them one of the most popular services in the entire Azure catalog.

Why Choose Azure VMs

Microsoft Azure holds a strong position as one of the top three cloud providers globally, and its virtual machine service is mature, reliable, and deeply integrated with other Azure services. You get access to hundreds of VM sizes optimized for different workloads, from general-purpose computing to memory-intensive databases and GPU-powered machine learning tasks.

The pay-as-you-go pricing model means you only pay for what you use, which makes Azure VMs cost-effective for both short-term experiments and long-running production workloads. Reserved instances let you lock in lower rates for one or three years if your usage is predictable. Azure also offers spot VMs at significantly reduced prices for workloads that can tolerate interruptions, which is great for batch processing or testing environments.

Azure Account Prerequisites Needed

Before you can create an Azure Virtual Machine, you need an active Azure account. If you do not have one, head to portal.azure.com and sign up. Microsoft offers a free tier that includes 750 hours of B1s VM usage per month for the first twelve months, along with a $200 credit for the first thirty days. This is more than enough to follow along with this guide at zero cost.

Once your account is active, make sure your subscription is set up correctly. A subscription is the billing container that holds all your Azure resources. Most individuals start with a single Pay-As-You-Go subscription. Enterprise users may have multiple subscriptions organized under a management group. Either way, confirm that your subscription is active and that you have the necessary permissions, specifically the Contributor or Owner role, before proceeding.

Choosing the Right VM Size

Azure organizes its VM sizes into series, each optimized for a specific type of workload. The B-series VMs are burstable and budget-friendly, ideal for development and light workloads. The D-series handles general-purpose computing. The E-series is memory-optimized for databases and in-memory analytics. The N-series includes GPU capabilities for machine learning and graphics-intensive tasks.

For most beginners setting up their first VM, the B2s or D2s v3 sizes offer a good balance of CPU, RAM, and cost. The B2s gives you 2 vCPUs and 4 GB of RAM, which is sufficient for web servers, small applications, and learning exercises. As your workload grows, Azure makes it straightforward to resize your VM without deleting and recreating it, which removes a lot of the pressure from your initial size selection.

Creating Resource Group First

A resource group is a logical container that holds related Azure resources together. Every VM you create needs to belong to a resource group. Before creating your VM, set up a dedicated resource group so you can manage, monitor, and eventually delete all related resources as a single unit rather than hunting them down individually across the portal.

To create a resource group, go to the Azure portal, search for Resource Groups in the top search bar, and click Create. Give it a meaningful name like vm-project-rg, select your subscription, and choose a region close to your physical location or your target users. The region you pick here will also be where your VM lives, so choose thoughtfully. Once the resource group is created, you are ready to start the VM setup process.

Starting VM Creation Process

In the Azure portal, search for Virtual Machines in the top search bar and click the Virtual Machines service. Hit the Create button and select Azure Virtual Machine from the dropdown. This opens the VM creation wizard, which walks you through configuration across several tabs including Basics, Disks, Networking, Management, Monitoring, and Advanced.

On the Basics tab, select your subscription and the resource group you just created. Give your VM a name that reflects its purpose, something like webserver-vm-01. Select the region that matches your resource group. For availability options, you can leave this as No infrastructure redundancy required for a basic setup. More complex production deployments would use availability zones or sets to protect against hardware failures.

Selecting Operating System Image

Azure offers a wide library of operating system images through the Azure Marketplace. On the Basics tab, click See all images next to the Image field to browse the full catalog. You will find Windows Server editions, Ubuntu, Debian, Red Hat Enterprise Linux, CentOS, and many pre-configured application images that bundle an OS with software like WordPress, LAMP stacks, or SQL Server.

For a general-purpose setup, Ubuntu Server 22.04 LTS is an excellent choice for Linux environments. It is stable, well-documented, and has strong community support. For Windows workloads, Windows Server 2022 Datacenter is the most current and feature-rich option. Choose based on the software you plan to run on the VM. The image selection determines which tools, package managers, and default configurations come pre-installed.

Configuring Authentication Settings

Azure gives you two authentication options for your VM: SSH public key for Linux VMs and password-based authentication for both Windows and Linux. SSH key authentication is more secure and is the recommended approach for any Linux VM, especially one that will be accessible over the internet. Password authentication is simpler to set up but more vulnerable to brute-force attacks.

To use SSH key authentication, you can generate a new key pair directly in the Azure portal by selecting Generate new key pair. Azure creates a private key file that you download and store securely on your local machine. Never share this file or store it in a public location. For Windows VMs, set a strong administrator password that meets Azure’s complexity requirements, which include uppercase letters, lowercase letters, numbers, and special characters.

Setting Up Networking Configuration

The Networking tab is where you define how your VM connects to the internet and to other resources within Azure. Azure automatically creates a Virtual Network, subnet, and public IP address for your VM if none exist yet. For a basic setup, the defaults work fine. For production environments, you will want to configure these resources manually to align with your network architecture.

The Network Security Group, or NSG, acts as a firewall for your VM. It controls which ports are open and which traffic is allowed in or out. By default, Azure opens port 22 for SSH on Linux VMs and port 3389 for RDP on Windows VMs. If you plan to host a web server, you will need to add inbound rules for port 80 for HTTP and port 443 for HTTPS. Be selective about which ports you open and restrict access by IP where possible.

Configuring Disk Storage Options

Azure offers three types of managed disks for your VM. Standard HDD is the cheapest option and works for development or low-traffic workloads. Standard SSD offers better performance at a moderate price and suits most general-purpose applications. Premium SSD delivers the best performance for production databases, high-traffic websites, and latency-sensitive applications.

Your VM comes with an OS disk automatically. You can add one or more data disks on the Disks tab to separate your application data from the operating system. This is a good practice because it makes backups simpler and allows you to resize or replace the OS disk independently. For most beginner setups, a single 30 to 128 GB Premium SSD for the OS disk is a solid starting point without unnecessary cost.

Reviewing and Launching VM

Before clicking Create, use the Review and Create tab to check all your configuration choices. Azure runs a quick validation to catch any missing required fields or conflicting settings. Review the summary carefully, paying attention to the VM size, region, OS image, authentication method, and networking settings. This is your last chance to catch a mistake before the VM starts incurring costs.

Once you click Create, Azure begins provisioning your VM. This typically takes two to five minutes. If you chose to generate a new SSH key pair, a popup appears prompting you to download the private key file. Download it immediately because you cannot retrieve it later. After provisioning completes, the portal takes you to the VM’s overview page where you can see its public IP address, status, and resource details.

Connecting to Your VM

For Linux VMs using SSH, open a terminal on your local machine and run the SSH command using your private key file and the public IP address shown on the VM’s overview page. The command looks like: ssh -i your-key.pem azureuser@your-public-ip. Make sure the private key file has the correct permissions by running chmod 400 your-key.pem before connecting, otherwise SSH will reject it for security reasons.

For Windows VMs, use Remote Desktop Protocol to connect. Download the RDP file directly from the VM’s overview page in the Azure portal and open it with the Remote Desktop client on your computer. Enter the administrator credentials you set during creation and accept the certificate warning. You will land on the Windows desktop and can begin working immediately. Azure Bastion is a premium alternative that lets you connect through the browser without exposing RDP to the public internet.

Installing Software on VM

Once connected, your VM is essentially a fresh server waiting for you to configure it. On Ubuntu, start by running sudo apt update and sudo apt upgrade to bring all packages up to date. Then install whatever software your use case requires. For a web server, sudo apt install nginx gets you started. For a development environment, you can install Python, Node.js, or any other runtime using the standard package manager.

On Windows Server, you can install roles and features through Server Manager or use PowerShell for scripting. Installing IIS for web hosting, SQL Server Express for databases, or any standard Windows application follows the same process as a physical Windows server. Azure VMs behave like real machines in every practical way, so any software that runs on a standard server will run on your Azure VM without modification.

Managing Costs Effectively

Azure VMs charge by the hour while they are running. If you are not using your VM, shut it down through the Azure portal by clicking Stop on the VM’s overview page. A stopped VM in Azure still retains its IP address and disk but stops compute charges. Deallocating the VM stops all charges except for storage, which is a small fraction of the total cost.

Setting up auto-shutdown is a smart move for development VMs that you only use during work hours. Find the Auto-shutdown option in the VM’s Operations menu and configure it to power down the VM automatically at a set time each day. This prevents the common mistake of forgetting a running VM over a weekend and coming back to an unexpectedly large bill. Budgets and cost alerts in Azure Cost Management also help you stay within spending limits.

Conclusion

Setting up an Azure Virtual Machine is a foundational skill that opens up a wide range of possibilities in cloud computing. From hosting websites and running development environments to supporting enterprise applications, the VM is one of the most versatile tools Azure offers. Once you understand the setup process, you can replicate it quickly and adapt the configuration for virtually any workload.

The steps covered in this guide give you everything needed to go from a blank Azure account to a fully running virtual machine. You learned how to create a resource group, select the right VM size and operating system, configure authentication securely, set up networking with proper firewall rules, attach and configure storage, and connect to your machine using SSH or RDP. Each of these steps builds on the last, and together they form a complete, repeatable workflow.

What makes Azure VMs particularly powerful is how well they integrate with the rest of the Azure ecosystem. As your skills grow, you can attach managed disks, configure load balancers, set up auto-scaling groups, connect your VM to Azure Monitor for performance tracking, and integrate with Azure Active Directory for centralized identity management. The VM you set up today can evolve into a sophisticated, highly available production environment without starting over from scratch.

Cost management is one area that deserves ongoing attention. Cloud costs can creep up if VMs are left running unnecessarily. Make it a habit to stop development VMs when not in use, explore reserved instances for predictable workloads, and review your Azure Cost Management dashboard regularly. These habits keep your cloud spending efficient and prevent bill shock, which is a common experience for cloud beginners who do not monitor usage closely.

Security should also grow alongside your VM usage. The basics covered here, including SSH key authentication, restricted NSG rules, and strong passwords, are a solid starting point. As you build more on Azure, look into Microsoft Defender for Cloud, Just-in-Time VM access, and Azure Policy to harden your environment further. The cloud rewards those who take security seriously from the beginning rather than bolting it on after a problem occurs.