Exercise – Connect to a virtual machine by using Azure Bastion

Completed

In this unit, you'll create a virtual machine (VM) to act as your internal app VM and deploy Azure Bastion to connect to it.

This exercise is optional. To complete it, you need access to an Azure subscription where you have permissions to create resources like a VM. If you don't have an Azure subscription, create a free account before you begin.

Create a resource group

Create a resource group to contain all the resources that you'll create for the exercises.

  1. Sign in to the Azure portal.

  2. Search for or select Resource groups.

  3. Select Create. The Create a resource group pane appears.

  4. On the Basics tab, enter the following values for each setting.

    Setting Value
    Project Details
    Subscription Select your subscription
    Resource group learn-bastion-rg
    Resource details
    Region Choose the region near you
  5. Select Review + create. After validation passes, select Create.

Create a VM

Create a Linux VM that's not exposed to the internet.

  1. In the Azure portal, search for or select Virtual machines.

  2. Select Create, and then select Azure Virtual machine from the dropdown. The Create a virtual machine pane appears.

  3. On the Basics tab, enter the following values for each setting. Leave any other settings as their defaults.

    Setting Value
    Project details
    Subscription Your subscription
    Resource group learn-bastion-rg
    Instance details
    Virtual machine name internalappvm
    Region Choose a region near you
    Image Ubuntu Server 20.04 LTS - x64 Gen2
    Administrator account
    Username azureuser
    SSH public key source Generate new key pair
    Key pair name internalappvm_key
    Internal port rules
    Public inbound ports None

    Use the default values for the rest of the settings on this tab.

  4. Select the Networking tab and enter the following values for each setting. Leave any other settings as their defaults.

    Setting Value
    Network interface
    Public IP None
    Public inbound ports None
  5. Select Review + create. After validation passes, select Create. The Generate new key pair dialog appears.

  6. Select Download private key and create resource.

    Screenshot of the Generate new key pair window with the Download private key button highlighted.

Because you created the internal app VM without a public IP, you can't connect to it over the internet. Instead of using a jumpbox VM to connect to the internal app VM, let's use Azure Bastion.

Create a subnet for Azure Bastion

Before you can use Azure Bastion, you need to create a subnet on the virtual network that the internal app VM uses.

  1. In the Azure portal, select or search for Resource groups.

  2. Select learn-bastion-rg.

  3. From the list of resources, select the virtual network learn bastion-rg-vnet.

  4. In the left menu pane, under Settings, select Subnets.

  5. In the top menu bar, select + Subnet to add a subnet. The Add subnet pane appears.

  6. Enter the following information to create a subnet.

    Field Name
    Name AzureBastionSubnet
    Subnet address range Enter an address space with a subnet mask that's /26 or larger, like /26, /25, and so on. An example is 10.0.1.0/24.

    Use the default values for the rest of the fields.

    Screenshot of the Add subnet page where the subnet name is AzureBastionSubnet.

  7. Select Save.

Deploy Azure Bastion

  1. In the Azure portal, select or search for Virtual machines.

  2. Select the virtual machine internalappvm.

  3. Select Connect > Bastion > Deploy Bastion.

    Screenshot of the Connect page and Bastion tab, with the Create Azure Bastion using defaults button.

Wait a few minutes for the Azure Bastion resource to be created.

Connect to the internal app VM

  1. After the Azure Bastion resource is created, you're prompted to enter credentials to connect to the VM.

  2. Enter the Username azureuser.

  3. Select SSH Private Key from Local File in the Authentication Type drop-down.

  4. For Local file, select the internalappvm_key.pem file that you downloaded when you created the VM.

    Screenshot of the Azure Bastion connection page with the user name and local file fields populated.

  5. Select Connect.

  6. In the remote shell, enter Linux commands like the following command that updates the system.

    Screenshot of a browser that shows an Ubuntu terminal session.

    sudo apt-get -y update
    
  7. When you're finished, enter exit.

The next time you want to connect to the internal app VM, go to the virtual machine, select Bastion, and enter your credentials.