Blog

Want to Create a Linux virtual machine? let us show you how.

Written by Adi | Feb 14, 2022 6:23:49 AM
  1. Type virtual machines in the search. 
  2. Under Services, select Virtual machines. 
  3. In the Virtual machines page, select Add. The Create a virtual machine page opens. 
  4. In the Basics tab, under Project details, make sure the correct subscription is selected and then choose to Create new resource group. Type myResourceGroup for the name.*.
  5. Under Instance details, type myVM for the Virtual machine name, choose East US for your Region, and choose Ubuntu 18.04 LTS for your Image. Leave the other defaults.
  6. Under Administrator account, select SSH public key. 
  7. In Username type azureuser. 
  8. For SSH public key source, leave the default of Generate new key pair, and then type myKey for the Key pair name.
  9. Under Inbound port rules > Public inbound ports, choose Allow selected ports and then select SSH (22) and HTTP (80) from the drop-down.

  10. Leave the remaining defaults and then select the Review + create button at the bottom of the page. 
  11. 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. 
  12. 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. 
  13. When the deployment is finished, select Go to resource. 
  14. On the page for your new VM, select the public IP address and copy it to your clipboard.

 

Connect to virtual machine 

Create an SSH connection with the VM. 

  1. If you are on a Mac or Linux machine, open a Bash prompt. If you are on a Windows machine, open a PowerShell prompt. 
  2. 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.

  

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. 

BashCopy 

sudo apt-get -y update 

sudo apt-get -y install nginx 

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.