Step-by-Step Guide to Creating and Connecting to a Linux VM Using a Public Key on Azure

Azure Virtual Machines (VMs) allow you to set up dedicated, on-demand computing resources like physical desktops or servers. Using a Linux VM provides the convenience of exploring the Linux operating system in a flexible, isolated environment, ideal for testing without affecting your primary system. The Azure portal simplifies this setup by configuring VM specifications, enabling SSH access, setting up networking, and finalising settings, allowing you to launch and work with your Linux VM efficiently.

Step 1: Sign in to Azure Portal

Open your web browser and go to Azure Portal.

Enter your Azure account email address and password to sign in.

Azure Portal Sign In page.

Step 2: Create a New Resource Group

In the Azure Portal, search for “Resource groups” in the search bar.

Click on “Create” and fill in the necessary details:

  • Subscription: Select your Azure subscription.

  • Resource group: Enter a name for your resource group.

  • Region: Choose a region close to you.

Add Screenshot: Resource Group creation page with fields filled in.

Step 3: Create a Virtual Machine

Type “Virtual machines” in the search bar and select it from the list.

Click on “Create” and then “Azure virtual machine”.

Fill in the basic details:

  • Subscription: Select your subscription.

  • Resource group: Select the resource group you created.

  • Virtual machine name: Enter a name for your VM.

  • Region: Choose the same region as your resource group.

  • Image: Select “Ubuntu Server 22.04 LTS”.

  • Size: Choose a VM size that fits your needs.

Virtual Machine creation page with fields filled in.

Step 4: Configure Administrator Account

Under the “Administrator account” section, select “SSH public key” for the authentication type.

Provide a username (e.g., azureuser).

Select “Generate new key pair” from the SSH public key source dropdown.

Download the private key file and save it securely.

Administrator account configuration with SSH public key selected.

Step 5: Configure Inbound Port Rules

Under “Inbound port rules”, select “Allow selected ports”.

Choose SSH (22) to enable SSH access.

Inbound port rules configuration with SSH (22) selected.

Step 6: Review and Create

Click on the “Review + create” button.

Review all the settings and click “Create” to start the deployment.

Review and create page with all settings reviewed.

Step 7: Connect to Your VM

Once the deployment is complete, go to the resource.

Copy the public IP address of your VM.

Open a terminal (Linux/Mac) or PowerShell (Windows).

Use the following command to connect to your VM:
ssh -i /path/to/your/private-key.pem azureuser@<public-ip-address>

Replace /path/to/your/private-key.pem with the path to your downloaded private key file and <public-ip-address> with the public IP address of your VM.

Terminal or PowerShell window showing the SSH command.

Step 8: Verify Connection

Once connected, you can run commands on your VM. For example, you can check the system information using:
uname -a

Terminal showing the output of the uname -a command.

Conclusion

Creating and connecting to a Linux VM using a public key on Azure enhances security and simplifies access management. This guide provides a comprehensive walkthrough to help you set up and connect to your VM efficiently.

If you have any questions or need further assistance, feel free to ask! Happy computing!

0
Subscribe to my newsletter

Read articles from Ozoemena Chigozie Daniel directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ozoemena Chigozie Daniel
Ozoemena Chigozie Daniel