In this blog, you will be taught how to create a Linux Virtual Machine running on Ubuntu image, how to connect to the virtual machine through a SSH protocol using a Public Key and go the extra mile of creating a web application, connect to it using the public key and lastly browse the web server.
SIGN IN TO AZURE PORTAL
To do anything on Azure portal, the first thing is to login to the portal (www.portal.azure.com) with your sign in details (Username and Password). You may need to register and sign up if you are a new user.
CREATE A VIRTUAL MACHINE ON AZURE PORTAL
After signing in, the next thing to is to create VM. The steps are as detailed below with images and annotations
Enter virtual machines in the search or select "Create a Resource" or select "Resource Group". any of the 3 will guide your steps.
In the Virtual machines page, select Create and then Virtual machine. The Create a virtual machine page opens.
In the Basics tab, under Project details, make sure the correct subscription is selected and then choose to Create new resource group or select an existing one. I entered PRENNIEX for sample purpose. Type in the preferred virtual name for your VM (PreshlinuxVM for me) , pick the other options as in the image
Let the security type be standard and choose Ubuntu Server 22.04 LTS - Gen2 for your Image. This is one of the differences between Windows Vm and Linux VM. Leave the other defaults. Size availability and pricing are dependent on your region and subscription. If you experience any error at any stage or during validation and its referencing the Region, please, option for another region.
Under Administrator account, select SSH public key. This basically indicates that you want to connect to your VM using public keys. In Username enter your desired username (PreshlinuxVM for me). For SSH public key source, leave the default of Generate new key pair, pick other options as in the image
Under Inbound port rules > Public inbound ports, choose Allow selected ports and then select SSH (22) and HTTP (80) from the drop-down. Then choose,
Leave the remaining defaults and then select the Review + create button at the bottom of the page.When the Generate new key pair window opens, select Download private key and create resource. Your key file will be download as PreshlinuxVM.pem. Make sure you know where the .pem file was downloaded; you will need the path to it in the next step.
CONNECT TO THE VIRTUAL MACHINE
Go to windows, search for Powershell and run as administrator
At your prompt, open an SSH connection to your virtual machine. Replace the IP address with the one from your VM, and replace the complete path to the .pem ( for this sample, the path is c:/user/prenniex/Downloads/PreshlinuxVM.pem) This is the path that the key file was downloaded. For sample sake, the command is as below
ssh -i c:/user/prenniex/Downloads/PreshlinuxVM.pem PreshlinuxVM@40.84.55.12
INSTALL A WEBSERVER
To see your VM in action, install the NGINX web server. From your SSH session, first update your package sources and then install the latest NGINX package with the commands below
**sudo apt-get -y update
sudo apt-get -y install nginx
**
BROWSE THE WEBSERVER
Use a web browser of your choice to view the default NGINX welcome page. Type the public IP address of the VM as the web address. The public IP address can be found on the VM overview page or as part of the SSH connection string you used earlier.
DO NOT FORGET TO CLEAN UP RESOURSES BY DELETING RESOURCE GROUPS AND THE RESOURCES THAT ARE NOT NEEDED.
GOODLUCK!
Top comments (0)