DEV Community

Cover image for How to Deploy and Connect to Linux Virtual Machine in Azure: Step by Step Guide
Celestina Odili
Celestina Odili

Posted on • Edited on

How to Deploy and Connect to Linux Virtual Machine in Azure: Step by Step Guide

Table of Contents
Create (Deploy) Linus Virtual Machine
Connect to Linus Virtual Machine
Testing

This guide shows how to deploy and connect a Linux virtual machine running Ubuntu Server 22.04 LTS-x64 Gen2 using SSH public key through Azure portal.

Create (Deploy) Linux Virtual Machine

Step 1: Sign in to Azure portal

Go to portal.azure.com and sign in. If you do not have a subscription yet, click here for sign up for free.

Step 2: Create a Linux Virtual Machine (VM)

a) Create a virtual machine
On the Home menu, click create a resource.

Image description

Locate virtual machine and click create.

Image description

This will open the basic tab of the create a virtual machine page.

b) Configure the VM Basics

Under the project details, select the subscription, create new resource group with any name of your choice or use an existing one.

Image description

Under Instance details, type a name for the VM and select a region. For the availability option, choose No infrastructure redundancy required. select standard for security type. For the image, select Ubuntu Server 22.04 LTS-x64 Gen2. leave the size at default.

Image description

Under Administrator account, select SSH public key then enter a username. You can use the default username if you wish. Select Generate new key pair for the SSH public key source and RSA SSH format for the SSH key type. Give a name for the key pair name. The default name is usually your VM name_key. You can change it if desired.

Image description

Under Inbound port rules, select Allow selected ports and check HTTP (80) and SSH (22) from the drop down.

Image description

c) Configure other Tabs (optional)
Having completed the basics tab then click review + create at the bottom of the page to provision the virtual machine or review each tab for full customization. Here, we will leave the other tabs at default setting.

Step 3: Review and Create (Deploy)

Click review and create at the bottom of the page.

Image description

Review the details and click create.
Image description

After validation is passed, a Generate new key pair window will open. Select Download Private key and create resource.

Image description

Your key file will be downloaded with a .pem extension.

**Note: **The location of the key file downloaded should be noted for easy connection through the terminal. You will need to reference the path when connecting to your VM.

back to top

Connect to Linux Virtual Machine

Step 1: Get Public IP Address.

When deployment is completed, click Go to resource.

Image description

On the new Linus VM, copy the public IP address

Image description

Step 2: Connect to the Virtual Machine

Create an SSH connection with the virtual machine. To achieve this, you will run a few commands in terminals. For a Mac or Linus user, use Bash prompt and set read-only permission on the .pem file. For windows user, use PowerShell or CMD and run as administrator.

When prompted on your opened terminal, open SSH connection by typing
ssh -i the path to the private key (the.pem file downloaded) username@public IP address
for example,
ssh -i "C:\Users\HP\Documents\Tina files\Linus-VM_key.pem" azureuser@52.232.125.22

Image description
If your connection is successful, you will get a welcome message.

Image description

Testing

To test if your VM is working, run a simple command to update the VM and install a web application (NGINX).

a) Update the VM
Type sudo apt-get -y update
and press enter
Image description

b) Install NGINX
Type sudo apt-get -y install nginx
and press enter

Image description

c) View in Browser

Open a browser and enter the public IP address of the VM created. The web application will open.

Image description

back to top

Top comments (0)