Various ways to create and connect to the Virtual Machine in Azure


In this guide, we'll walk through the process of creating a Virtual Machine (VM) in Azure and connecting to it using three different methods:

  1. Azure Portal (UI-based)

  2. Azure CLI (Command Line Interface)

  3. PowerShell (Azure PowerShell Module)

We'll also cover how to connect to the VM via RDP (for Windows) or SSH (for Linux).

Create and Connect to a VM Using the Azure Portal (UI)

Step 1: Create the Virtual Machine

  1. Sign in to the Azure Portal:
    Go to and sign in with your credentials.

  2. Create a Virtual Machine:

    • In the left sidebar, click on "Create a resource".

    • Search for "Virtual Machine" and select it.

    • Click "Create".

  3. Configure the VM:

    • Subscription: Select your subscription.

    • Resource Group: Create a new or select an existing one.

    • VM Name: Enter a name (e.g., MyVM).

    • Region: Select the region (e.g., East US).

    • Image: Select the operating system image (e.g., Windows Server 2022 or Ubuntu 20.04).

    • Size: Select a size (e.g., Standard B1s for a small VM).

  4. Authentication:

    • For Windows, use a Username and Password.

    • For Linux, use SSH public key or Password.

  5. Inbound Port Rules: Select Allow selected ports and choose RDP (3389) for Windows or SSH (22) for Linux.

  6. Networking:

    • Configure the Virtual Network (VNet), Subnet, and Public IP Address.

    • Ensure a Public IP Address is selected for remote access.

  7. Disks: Select your preferred disk type (e.g., Standard SSD).

  8. Review & Create: Review your settings and click "Create" to deploy the VM.

Step 2: Connect to the Virtual Machine

  1. Navigate to the VM: Once the VM is deployed, go to Virtual Machines in the Azure portal and select the VM you just created.

  2. Get the Public IP Address: On the VM overview page, note down the Public IP Address.

  3. For Windows VM (RDP):

    • Open Remote Desktop Connection on your local machine.

    • Enter the Public IP address of the VM.

    • Enter the username and password when prompted.

  4. For Linux VM (SSH):

    • Open a terminal (Linux/macOS) or an SSH client (Windows).

    • Use the command:

    • If you're using an SSH private key, specify it using:

Create and Connect to a VM Using Azure CLI

Step 1: Install Azure CLI

  1. If you don’t have Azure CLI installed, you can install it by following the instructions on Azure CLI installation.

Step 2: Log in to Azure CLI

  1. Run the following command to log in:

  • This will open a browser for authentication.

  • Once you’re authenticated, you can use Azure CLI commands.

Step 3: Create the Virtual Machine

Use the following command to create a new VM:

For Windows VM:

For Linux VM:

For Linux: This command generates an SSH key pair for authentication.

Step 4: Get the Public IP Address of the VM

To retrieve the public IP address, use:

Step 5: Connect to the Virtual Machine

For Windows (RDP):

  • Use the following command to get the RDP file:

  • Then connect using Remote Desktop Connection.

For Linux (SSH):

  • If using SSH, connect with the following command:

  • Use the SSH key if you generated one during creation, or provide the password for authentication.

Create and Connect to a VM Using Azure PowerShell

Step 1: Install Azure PowerShell

If you don't have Azure PowerShell installed, follow the installation guide here.

Step 2: Log in to Azure PowerShell

Run the following command to log in to your Azure account:

Step 3: Create the Virtual Machine

For Windows VM:

For Linux VM:

Step 4: Get the Public IP Address of the VM

Step 5: Connect to the Virtual Machine

  1. For Windows (RDP): Use the Remote Desktop app and connect using the Public IP address and credentials.

  2. For Linux (SSH): Open a PowerShell terminal and run:

Summary

This guide showed how to create and connect to a Virtual Machine in Azure using three different methods:

  1. Azure Portal: A UI-based approach for those who prefer graphical interfaces.

  2. Azure CLI: Command-line interface for managing resources, especially suited for automation and scripting.

  3. Azure PowerShell: Ideal for those familiar with PowerShell or working in environments where PowerShell is the standard.

Each method provides flexibility for managing and connecting to your Azure VM, whether you’re using RDP for Windows or SSH for Linux.

Related Articles


Rajnish, MCT

Leave a Reply

Your email address will not be published. Required fields are marked *


SUBSCRIBE

My newsletter for exclusive content and offers. Type email and hit Enter.

No spam ever. Unsubscribe anytime.
Read the Privacy Policy.