DEV Community

Cover image for Creating and connecting to a Linux VM using a public key.
Akinsooto Abidemi
Akinsooto Abidemi

Posted on

Creating and connecting to a Linux VM using a public key.

Creating a Linux Virtual Machine (VM) on Azure is straightforward and allows for secure and efficient management of your server. In this guide, we will walk you through the steps to set up a Linux VM using the Azure portal and connect to it using a public key.

Step 1: Login to access the Azure Portal
Step 2: Start Creating a Virtual Machine
Step 3: Configure Basic Settings
Step 4: Configure the Administrator Account
Step 5 : Review and Create the VM
Step 6: Connect to Your VM

Step 1: Log in to your Azure account. If you don’t have one, you’ll need to sign up for an account at Azure.

  • Open your web browser and go to the Azure Portal.
  • Sign in with your Microsoft account credentials.

Once you’re logged into the Azure Portal:

Step 2: Click on Create a Virtual Machine.

Image description

Step 3: You will now set up the basic configuration for your VM.

Basics:

Subscription: Choose your Azure subscription.
Resource group: Select an existing resource group or create a new one to organize your resources.
Virtual machine name: Provide a unique name for your VM.
Region: Choose the location closest to you or where you want to host your VM.
Availability options: Select based on your needs for redundancy and availability.

Image: Ensure the selected image matches your desired Linux distribution (e.g., Ubuntu Server 20.04 LTS).

Image description

Size: Click on Change size and choose the appropriate VM size based on your performance needs and budget.

Step 4: Configure the Administrator Account
For secure access to your VM, you’ll set up authentication using an SSH public key.

In the Administrator account section:
Select SSH public key as the Authentication type.

Image description

Enter your key pair name and choose your inbound rules. Then click on Review + Create.

Image description

Step 5: Choose the first option which is to download private key and create resource.

Image description

Go to resource.

Image description

Copy the public address as shown in the image below:

Image description

Step 6: Then go to your command prompt, open as an administrator.

Type in ssh -i "C:\Users\Abidemi\Downloads\abidemi-linux-vm_key.pem" azureuser@13.82.195.115 using your copied public address.

Image description
If you type the public IP address on your browser it pops up this page as seen below:

Image description

Type in these commands:
sudo apt-get -y update
sudo apt-get -y install nginx

Image description

Then refresh the browser.

Image description

Summary
That's it! We've successfully created and connected to a virtual machine on Azure using SSH public key authentication. Let me know if you need any more guidance!

Top comments (0)