Steps on Creating and Connecting to a Linux VM Using a Public Key.

Steps on Creating and Connecting to a Linux VM Using a Public Key.

A Guide to Securely Setting Up and Accessing Your Linux Virtual Machine with SSH Public Key Authentication

What is a Linux Virtual Machine (VM)?

A Linux Virtual Machine (VM) is a software-based emulation of a physical computer that runs a Linux operating system (OS).

How to Create a Linux VM

  1. Login to your Azure account through the Azure portal

  1. Click on “Virtual Machines“

  1. Click on “Create“ and choose “Azure virtual machine".

  1. Fill the “Basics“ tab such as Resource group, Region, Availability zone, Security type and so on.

a.) In the “Image“ field, select and Linux OS. Ubuntu Server 22.04 LTS -x64 Gen2 is a type of Linux OS

b.) Choose the size of the VM. The bigger the size, the higher the cost of the VM.

c.) For the sake of this blog, we will choose the “SSH public key” authentication type which is mostly industrial best practice. However, any of the options can work just fine.

d.) There is a default “Username: azureuser”. Though, the parameter can be changed to suit the user’s purpose. It is needed to login to the VM.

e.) Using the dropdown arrows gives you other options to choose for the “SSH public key source”. For instance, you do not need to “generate a new key pair“ if you already have an existing one.

f.) “Key pair name“ automatically generates a name.

g.) Select inbound ports 22 and 80 for SSH and HTTP (web) respectively.

  1. Click on “Review + Create“

  1. Watch out for the validation passed message to confirm the successful creation of your VM

  2. Click “Create“

  1. On the dialog box that comes up, select “download private key and create resource“. A file is downloaded to your computer.

  1. Click on “Go to resource“ after “Your deployment is complete“ message is shown on your screen.

  1. The overview in formation of your VM is revealed such as status, public IP address, VM name, size and lots more.

  1. Go to the “Search“ field on your computer “Task bar“.

  2. Type CMD which is the short form of Command Prompt. Then “Run as administrator“.

  1. A window with a black background comes up. Type in the following command: ssh -i location\filename user@public_ip_address.

    ssh -i C:\Users\Kadex\Documents\Ka\Cloud\cov_key.pem azureuser@5.25.10.192

If you see user@vm_name in “green” lettering, then you have successfully logged in to the VM.

Note: Location is that of the file that was downloaded to your computer (step 8)

Filename is the name of the file that was downloaded

User is the name of the user that is registered with the VM (step 4d)

Public IP address is the logical address that points to the VM.