Setting Up a Linux Virtual Machine with Azure & Nginx on a MacOs using Password Authentication (Part I)
Tags: azure, virtualmachine, cloud, linux
Published: 2024-05-29 03:41:40

---
title: Setting Up a Linux Virtual Machine with Azure & Nginx on a MacOs using Password Authentication (Part I)
published: true
description: A step-by-step guide on setting up a Linux virtual machine in Azure portal using Password Authentication.
tags: azure, virtualmachine, cloud, Linux
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k5w11lfpn2arb6xa0tub.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2024-05-12 13:22 +0000
---

# Introduction

This is the first installment of a two-part post focused on creating a Linux virtual machine with Azure. If you have been following my journey into cloud development, I have written about setting up a Windows virtual machine in Azure too. 


Two authentication approaches can be used to set up the Linux virtual machine. This post will focus on one which is the **password authentication**

As I have suggested in previous posts about setting up virtual machines, having a Microsoft and an Azure account is a prerequisite for following the steps in this post. 


##Step 1: Create a Linux Virtual Machine


- Log in to Azure portal
![Azure Portal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/61wx4ccx53hpcecds79c.png)

- Search **Virtual Machine** using the search bar at the top of the page.

![Search Bar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zeubxdgockduyh6aqnlt.png)


- Click the **+ Create** icon at the top of the page or click the **Create** button at the bottom to create a virtual machine.
![create buttons](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxxhg4gerkmjs3ciaux1.png)
![Azure Virtual Machine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csazwupisohyra6pbxyp.png)

###Basics Tab


![Basics Tab](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53m4g5kqdv9tkk9bt6ob.png)
- Under **Project details**, name the **Resource Group** or choose a **Resource Group**
![Project details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gnttr7bnhij2raaba8mu.png)

![Resource group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o191lyzbs3zcrzrldo04.png)

- Next, give the Virtual Machine a name.

![Virtual machine label](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sauzsbcbd86sorc79p86.png)

- At the **Region** label, select an appropriate label.
![Region](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/whcor73us518yqgymvj4.png)

- For the **Availability Options** label, select **Availability zone**.

![Availability Options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1lrusjn6sa4o8lsk4xc7.png)

- At the **Availability zone** label, select zone 2 (I selected zone 2 in mine. However it may be different in yours).

![Availability zone](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kgud9lmep635s3kx0ec5.png)

- **Security type** label should be set at **Trusted launch Virtual Machines**

![Security type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/95wvycuo7548cwrx8vp3.png)

- The **Image** label should be set to **Ubuntu Server 22.04 LTS x64 Gen2**

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

- **VM Architecture** should be set to **x64**.
![VM Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d2crl7oz9jawebgmarh5.png)

- Do not tick **Run with Azure spot discount** box
![Run with Azure spot discount](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8j0kwegenfucfw7f38n.png)

- Set **Size** to **Standard_B2as_V2..**
![size](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dl20mgj0nlet931ql746.png)

- Do not tick **Enable Hibernation** box as well.

![Enable Hibernation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vdbhxq498vb1yboouc1.png)

- Under **Administrator Account** heading, Set **Authentication type** to **Password**. I will handle **SSH** Authentication in part two of this post.

![Authentication type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z9sxuw0h6ynr73tiu2l4.png)

- Set **Username**, **Password** and **confirm Password** subsequently.

![username & password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/il42nq2xzlg80anezd3m.png)

![username](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98j556q31t6b94tre1yz.png)

- At **Public inbound ports** label, select **Allow selected ports**, and
![Public inbound ports](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p543h6fbo9h39ob0s7iy.png)
 
- for the **Select inbound ports** label, at the dropdown, tick **HTTP (80)** and **SSH (22)**. **HTTP** was selected as part of the ports because I will access the server via a browser at some point in this post.

![Select inbound ports](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bja6z3nq9ne9gjwptaq.png)

![HTTP & SSH](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1sha0bwnyam6usir7vi.png)

###Monitoring  Tab

- Click **Monitoring** at the top of the page
![Monitoring](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2p3dniy30pvhoihyrerb.png)
- Click **Disable** to disable diagnostics. This is to prevent third-party access.
![Disable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l48b1lq8g1g13kalnct0.png)

###Tags  Tab

- Under the Tag Tab it is ideal that name and value are created for the resources. Give the resource a name and value In the annotated part of the image below. They help to categorize resources. Both the name and value are called Tags.

![Tags](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2u4z2kvb5bvvut2uw12d.png)

- Click the **Review + create** tab or the **Review + create** button at the bottom of the page.
![Review + create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8kn0eso6nxgmcxvpdegm.png)

- Click the **Create** button to complete the configuration process.
![Create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9qra7sr5p87eqvgingy.png)
![initialising deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4yppaxvuvkxtlch1da7n.png)
- After the complete deployment, click the **go to resources** button. This completes the creation of the virtual machine.

![go to resources](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jwdr2b22zn64tv4iv79c.png)

- The next thing to do is to increase IP address timeout to prevent untimely shutdown. 

- At the Virtual Machine overview page, click on the IP address at the **IP address label**
![IP address](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jwdr2b22zn64tv4iv79c.png)

- This re-directs to an IP configuration page. While on the page move the idle timeout slide to the right hand of the page.

![IP configuration page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rj0m0b74ws3vybbqvdkm.png)

- Click the **Save** icon at the top of the page.
![Save](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ptxoxr8ou2kost7od3f8.png)
- Close this page by clicking the close icon at the top right. 
![close icon](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dk055y359gs0azh2xz6r.png)
- Copy the IP address at the Virtual machine interface.

##Step 2: Connect to the Linux Virtual Machine

- To connect to the Linux Virtual Machine, Open the terminal.
- Type in **ssh username@IP address** at the terminal. The Username used here was created while providing information for the Administrator account in the above steps, while the **IP address** was copied when the deployment process was complete. 
![terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mytibz23eg5shr77pm4o.png)

- The prompt asks if you want to continue, type **yes**

![prompt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x3di9feqhi248bhdxsq1.png)

- Provide the required login password when prompted again.
- Then the prompt changes to a combination of the **username@virtual_Machine_Name**. This is evidence of a connection to the Linux Virtual Machine.

![proof of connection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i5jddl5igosi7d8p9l2w.png)

##Step 3: Install Nginx Server in the Virtual Machine

- The next step is installing a **Nginx** server in the Linux Virtual machine. To do this, log in as the **root** in the Virtual Machine.
At the terminal type in **sudo su** to change to **root** user.
![root user](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i6o3g58hmiwb4okviixq.png)

- At the next terminal/prompt type **apt install nginx** to install ngix.
![Nginx](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0cfpswkilkreoa30xxtq.png)

- Select **yes** at the next prompt. This completes the Nginx installation process.
![another prompt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y2gw3pyc1ir4tisrkt8m.png)

##Step 4: Testing the Linux virtual Machine via browser

- To test if everything works perfectly, copy the Linux Virtual Machine **IP address** from the Azure portal and paste it into a browser. If you can see the image below in your browser, it means everything is working well.

![Browser confirmation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lxchg7p3nkpqbeif3akg.png)


# Conclusion

This concludes my post on creating a Linux Virtual machine in Azure using Password Authentication. 
It is advised that the resource created in the Azure portal be deleted when not used. 
In the next post, I will write about creating a Linux Virtual machine in Azure using  **SSH** Authentication.