how to create and run a virtual machine in Azure

Creating a virtual machine (VM) in Microsoft Azure is an easy process that allows you to run a fully functional computer within the cloud. This article will walk you through the steps to create a VM in Azure, from setting up your account to configuring the VM settings.

1. Prerequisites

Before creating a VM in Azure, ensure you have the following:

  • A valid Azure account. If you don’t have one, sign up for a free trial.
  • Familiarity with Azure Portal and basic concepts of virtualization.

2. Creating a Virtual Machine

  1. Log in to the Azure Portal.
  2. In the left-hand menu, click Create a resource.
  3. In the search bar, type virtual machine and select Virtual Machines from the dropdown list.
  4. Click Create to open the VM creation wizard.

3. Configuring the Virtual Machine

The VM creation wizard will guide you through the following steps:

  1. Basics: Enter the following details:
    • Subscription: Choose the subscription you want to use.
    • Resource group: Create a new resource group or select an existing one.
    • Virtual machine name: Give your VM a unique name.
    • Region: Choose the geographic region where your VM will be hosted.
    • Availability options: Select an availability set or zone, if required.
    • Image: Choose the operating system for your VM.
    • Size: Select the VM size based on your needs (CPU, memory, storage).
    • Authentication type: Choose between SSH public key or password for authentication.
    • Username: Enter a username for your VM.
    • Password / SSH public key: Provide a password or SSH public key, depending on the authentication type you selected.
  2. Disks: Configure the storage settings for your VM:
    • OS disk type: Select the type of storage (Standard HDD, Standard SSD, or Premium SSD).
    • Data disks: Attach additional data disks if needed.
  3. Networking: Configure the networking settings for your VM:
    • Virtual network: Select an existing virtual network or create a new one.
    • Subnet: Choose the appropriate subnet for your VM.
    • Public IP: Assign a public IP address or create a new one.
    • NIC network security group: Choose the network security group for your VM.
    • Accelerated networking: Enable or disable accelerated networking.
    • Load balancing: Configure load balancing options, if required.
  4. Management: Configure monitoring and auto-shutdown settings.
  5. Advanced: Configure additional settings such as extensions, cloud-init, and host groups.
  6. Tags: Add tags to your VM for better organization and management.
  7. Review + create: Review your VM configuration and click Create to deploy the VM.

4. Connecting to the Virtual Machine

Once the VM is created, you can connect to it using either SSH (for Linux VMs) or Remote Desktop Protocol (RDP, for Windows VMs).

. To find the public IP address of your VM, navigate to your VM’s Overview page in the Azure Portal.

  1. For Linux VMs, open a terminal and use the following command to connect via SSH:
  1. Replace <username> with the username, you specified during VM creation and <public-ip-address> with the public IP address of your VM.
  2. For Windows VMs, use the Remote Desktop Connection app (built into Windows) or a third-party RDP client:
    • Open the Remote Desktop Connection app.
    • Enter the public IP address of your VM and click Connect.
    • When prompted, enter the username and password you specified during VM creation.

5. Conclusion

Congratulations! You’ve successfully created a virtual machine in Microsoft Azure. You can now start using your VM to host applications, store data, or perform any other tasks that you would on a physical machine. Remember to monitor usage and adjust resources as needed to optimize performance and control costs.