DEV Community

Cover image for How To Create and Connect To Linux Virtue Machine Using A Public Key
Abisola Adesegun
Abisola Adesegun

Posted on • Edited on

How To Create and Connect To Linux Virtue Machine Using A Public Key

Table of contents
Step 1: Sign in to Azure Portal
Step 2: Configure Basic Settings
Step 3: Review and Create Virtue Machine
Step 4: Create the Virtual Machine
Step 5: Connect to virtual machine
Step 6: Install web server
Step 7: View the web server in action

In this blog, I'll be creating an Azure Virtual Machine
Below are step-by-step instructions:

Step 1: Sign in to Azure Portal
Go to the Azure Portal (portal.azure.com) and sign in using your Azure account credentials.

Step 2: Configure Basic Settings

  • Search for Virtual machines. In the Virtual machines page, select โ€œ+ Createโ€ and select Virtual machine them virtual machine page opens.

Image description

  • In the Basics tab, under Project details, make sure to select the right subscription and then either select an existing resource group or choose to Create new resource group.

Image description

  • Under Instance details, enter the Virtual machine name, and choose Ubuntu Server 22.04 LTS - Gen2 for your Image. Leave the other defaults.

Image description

  • Under Administrator account, select SSH public key. Enter azureuser as the username.

Image description

  • For SSH public key source, leave the default of Generate new key pair, and then enter the Key pair name. Under Inbound Ports, this is the port that we will be using to connect to our Virtual Ubuntu Machine and then select SSH (22) and HTTP (80) from the drop-down.

Image description

Leave the remaining defaults and then select the Review + create button at the bottom of the page.

Step 3: Review and Create Virtue Machine

Review your settings and make any changes if required.

Image description

Step 4: Create the Virtual Machine

  • After clicking on "Create," Azure will start deploying your virtual machine. It may take a few minutes for the deployment to complete.

Image description

  • When the Generate new key pair window opens, select Download private key and create resource.

Image description

  • When the deployment is finished, select Go to resource.

Image description

  • On the page for your new VM, select the public IP address and copy it to your clipboard.

Image description

*Step 5: Connect to virtual machine *

Create an SSH connection with the VM.

  • On your Windows computer, open a PowerShell prompt.

  • At your prompt, open an SSH connection to your virtual machine. Copy and paste the IP address on your Virtual machine.

Then type in the below command,

ssh -i "/path/to/your/private-key-file.pem" Username@Public IP Address

Step 6: Install web server

To know if your VM is working, install the NGINX web server via either Command Prompt or Powershell Prompt.

Type the below commands one after the other

sudo apt-get -y update
sudo apt-get -y install nginx

When done, type exit to leave the SSH session.

Step 7: View the web server in action

Use any web browser of your choice to view the default NGINX welcome page. Tycopy amd paste the public IP address of the VM as the web address.

Image description

Top comments (0)