How To Create a Linux virtual machine in the Azure portal. by moses emeka
Tags: azure, linux, virtualmachine, cloud
Published: 2024-07-03 19:38:38

[Sign in to Azure
Create virtual machine
Connect to virtual machine
Install web server
View the web server in action
Clean up resources ](url)

## Applies to: ✔️ Linux VMs

Azure virtual machines (VMs) can be created through the Azure portal. The Azure portal is a browser-based user interface to create Azure resources. This quickstart shows you how to use the Azure portal to deploy a Linux virtual machine (VM) running Ubuntu Server 22.04 LTS. To see your VM in action, you also SSH to the VM and install the NGINX web server.

If you don't have an Azure subscription, create a free account before you begin.
Sign in to Azure
## Sign in to the Azure portal.

## **Create virtual machine**

 Enter virtual machines in the search

 Under Services, select Virtual machines.

In the Virtual machines page, select Create and then Virtual machine. The Create a virtual machine page opens.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tu7qjz2660jd5j2g4r11.PNG)

In the Basics tab, under Project details, make sure the correct subscription is selected and then choose to Create new resource group. Enter myResourceGroup for the name


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfwdg3kgjsuv1hcbbsc8.PNG)

Under Instance details, enter myVM for the Virtual machine name, and choose Ubuntu Server 22.04 LTS - Gen2 for your Image. Leave the other defaults. The default size and pricing is only shown as an example. Size availability and pricing are dependent on your region and subscription


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0kqpc35vejiu1n6ka1iw.PNG)

Under Administrator account, select SSH public key

In Username enter azureuser.

For SSH public key source, leave the default of Generate new key pair, and then enter myKey for the Key pair name.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ccx8nu58i27rsk8l6fs.png)

Under Inbound port rules > Public inbound ports, choose Allow selected ports and then select SSH (22) and HTTP (80) from the drop-down


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5hpznk6dyfaf04yq8w5n.png)


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

On the Create a virtual machine page, you can see the details about the VM you are about to create. When you are ready, select Create

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cgolyeijw5szrqu45v2x.PNG)


When the Generate new key pair window opens, select Download private key and create resource. Your key file will be download as myKey.pem. Make sure you know where the .pem file was downloaded; you will need the path to it in the next step.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4n7sykx85rdaapbzf9u.PNG)

When the deployment is finished, select Go to resource.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/icjtip8kodtg9pbdrg6c.PNG)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gffrrdtysy43arq3ecao.PNG)


## Connect to virtual machine

If you are on a Mac or Linux machine, open a Bash prompt and set read-only permission on the .pem file using chmod 400 ~/Downloads/myKey.pem. If you are on a Windows machine, open a PowerShell prompt

At your prompt, open an SSH connection to your virtual machine. Replace the IP address with the one from your VM, and replace the path to the .pem with the path to where the key file was downloaded.

ssh -i C:/users/EMMYFURTHER/Downloads/myKey.pem azureuser@10.111.12.123


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x5jnabrd92oq752ord1m.PNG)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/svtghbn37uqjwf19ety1.PNG)

## Install web server

To see your VM in action, install the NGINX web server. From your SSH session, update your package sources and then install the latest NGINX package


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i984ytc4sn8wng3cz38j.PNG)

When done, type exit to leave the SSH session.

## View the web server in action

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwfavnrvtd0wj6ad3e3g.PNG)

## Clean up resources

## Delete resources

When no longer needed, you can delete the resource group, virtual machine, and all related resources.

1. On the Overview page for the VM, select the Resource group link

2. At the top of the page for the resource group, select Delete resource group.

3. A page will open warning you that you are about to delete resources. Type the name of the resource group and select Delete to finish deleting the resources and the resource group.