DEPLOYING A LINUX VIRTUAL MACHINE IN AZURE
Tags: azure, linux
Published: 2024-04-15 06:24:10

Embarking on the journey of deploying a Linux virtual machine opens up a world of possibilities within the dynamic landscape of cloud computing.
In this comprehensive guide, we delve into the intricacies of provisioning a Linux-based virtual machine (VM) on the Azure platform. This article serves as your compass, guiding you through every step with clarity and precision. Whether you're a seasoned IT professional or an aspiring enthusiast, join me as we unravel the intricacies of deploying a Linux VM, empowering you to harness the full potential of cloud infrastructure with confidence.

## CREATING A LINUX VIRTUAL MACHINE

1) Sign in to Azure Portal

Sign into the azure portal to get started. If you don't already have an account, _<a href="https://go.microsoft.com/fwlink/?linkid=2227353&clcid=0x409&l=en-us&srcurl=https%3A%2F%2Fazure.microsoft.com%2Ffree">Click here</a>_ to create a free account. 
Now that you're all set, let's begin!

2) In the search bar, type 'Virtual Machine'.

3) From the search results, select the highlighted virtual machine from the displayed list of resources. 

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

You will be directed to the 'Virtual machines' page. 

4) Click on the create dropdown and select the highlighted VM from the menu.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1jgnu3p83fx107196a0g.jpeg)

You will be directed to the 'Basics' page.

### **Project Details**

#### Subscription

An Azure subscription is essentially a billing and account management container within Microsoft Azure. When you sign up for Azure, you create a subscription and all the resources you create within Azure are associated with that subscription. You can learn more about [Azure Subscription](https://www.googleadservices.com/pagead/aclk?sa=L&ai=DChcSEwjt0IimyryFAxXsYUcBHQWzARoYABAAGgJxdQ&ase=2&gclid=CjwKCAjwt-OwBhBnEiwAgwzrUt_CwHx1pTrtniWzeU_Ol-QB4N5M0hyeGILOVvFUOhLIx1mPMtFfLBoC1oQQAvD_BwE&ei=FRwZZtSPAoDzi-gP06KIsAw&ohost=www.google.com&cid=CAESV-D2EfgXokIJAzL2MjlRhFoZeSdFUtlto7p4Ks4R6hJcIrcI6IMv6hTteUcI_DEzHgkJyyYIhjQNevfLrio1PoV17FotIx8Ru9zJwzvufSa8jhmNxKnGzA&sig=AOD64_2W4X3klNLnrMcASfKv4rbBoZHKOA&q&sqi=2&nis=4&adurl&ved=2ahUKEwiU7v-lyryFAxWA-QIHHVMRAsYQ0Qx6BAgIEAE) on the official Microsoft documentation website.

#### Resource group

5) Select an earlier created resource group from the drop down or create a new resource group. 

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

### **Instance Details**

6) Name your Virtual Machine. Be sure to adhere to the naming conventions expected by Azure.

7) Select a region from the drop down. Note that the region of your resource can be different from that of your resource group.
Proximity and cost are important factors to consider when selecting an Azure region. _<a href="https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-setup-guide/regions#:~:text=Proximity%20is%20an%20important%20factor,to%20your%20on%2Dpremises%20systems.">Read more</a>_ about choosing a suitable region.

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

8) Select an Availability Zone

In Azure, an availability zone is a unique physical location within an Azure region. Each zone is made up of one or more data centers equipped with independent power, cooling, and networking infrastructure. Azure availability zones are designed to provide high availability and resiliency for applications and data by ensuring that they are isolated from failures in other zones within the same region.

By deploying resources across multiple availability zones, you can protect your applications and data from failures due to hardware or network issues in a single zone. This helps to ensure that your services remain available and resilient even in the face of unexpected events.

9) Select a Security type

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

10) Select an Image Type

In Azure, the term 'image' typically refers to the template or snapshot that defines the operating system, software configuration, and other settings for the VM. 

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

11) Leave the VM architecture and Run with _<a href="Learn more about Azure Spot instances.">Azure Spot</a>_ discount fields as default.

12) Select a suitable size for your VM.

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

### Inbound Port Rules

In Azure, inbound port rules refer to the configurations that control access to resources within your Azure environment from external sources, such as the internet or other networks. These rules are typically managed through Azure Network Security Groups (NSGs) or Azure Firewall, which allow you to define filtering rules based on source and destination IP addresses, ports and protocols.

13) Select the SSH option from the drop down.

SSH (Secure Shell) port is the default port used for establishing secure remote shell connections to a server or device using the SSH protocol. The default port number for SSH is 22.

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

### **Administrator Account**

14) Select an Authentication Type.

In Azure, Linux virtual machines (VMs) support two authentication methods for accessing and managing the VMs. They include:

**SSH Key Authentication**

SSH (Secure Shell) key authentication is the most common method used to authenticate with Linux VMs in Azure.
With SSH key authentication, you generate a public-private key pair on your local machine. 
When you attempt to connect to the VM via SSH, your local SSH client uses the private key to authenticate with the VM. If the private key matches the public key stored on the VM, access is granted.
SSH key authentication provides a high level of security and comes highly recommended for SSH access to Linux VMs in Azure.

**Password Authentication**

Password authentication involves logging in to the Linux VM using a username and password combination.
When creating the Linux VM in Azure, you have the option to specify a username and password. You use these credentials to log in to the VM via SSH.
While password authentication is straightforward, it's generally considered less secure than SSH key authentication because passwords can be susceptible to password guessing attacks or interception.

**Authentication via SSH public key**

a) Select the SSH public key option
b) Fill in a username
c) Select 'Create Generate new key pair'
d) Give your key pair a name

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ffs6l6zms6ij5h4ij5h.jpeg)

**Authentication via Password**

a) Select the Password option
b) Fill in a username
c) Fill in your password

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71kgwjylukd5pomqhkfk.jpeg)

### Disks

_<a href="https://dev.to/temiloluwa_adediji/demystifying-azure-disks-from-creation-to-initialization-1chb.">Learn more about Azure Disk</a>_

15) Click on the OS disk type dropdown and select Standard SSD or any disk type of your choice. Maintain the default values of other fields

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53tjjyxdn8u1jnyi40jy.jpeg)

16) Maintain the networking, management, monitoring and advanced and Tag pages as default.

17) Click on 'Review+create'

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

18) Review the summary of your VM configuration and click on 'Create' to start the deployment process.

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

19) For the SSH public key, you will be prompted to download the private key. Go ahead to download.

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


20) Once the deployment is complete, click on 'Go to resource'. This takes you to the Overview page of your VM.

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


## CONNECTING TO YOUR LINUX VIRTUAL MACHINE


### Using the SSH public key

1)  Select connect from the drop down menu as show.

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

2) Scroll down and click on 'select' on the Native SSH pane.

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

3) Locate the earlier downloaded private key and copy the path. To do this, right click, hold down the 'options' key and select the 'Copy as Pathname' option.

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

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

4) Return to azure and paste the copied path into the field as shown.

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

5) Copy the SSH command as below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vgri01zijca28taopwn.jpeg)

6) Open up your Mac terminal and type in 'pwsh' followed by 'return' key. If you don't already have powershell instead, use this _<a href="https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-macos?view=powershell-7.4">guide</a>_ for installation.

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

7) Paste the SSH command into your terminal followed by the return key.

8) You will be prompted to continue, enter 'yes' and then the return key.

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

9) A welcome message will be displaced as shown below.

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


### Using the Password Authentication

1)  Select connect from the drop down menu as show.

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

2) Copy the Public IP of your VM from the overview page.

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

3) Open up your Mac terminal and type in 'pwsh' followed by 'return' key. If you don't already have powershell instead, use this _<a href="https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-macos?view=powershell-7.4">guide</a>_ for installation.

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

2) Input the following SSH command: ssh username@IP. For example : ssh Temiloluwa@20.51.206.27

3) You will be prompted to continue, enter 'yes' and then the return key.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9fbzgchpcatrg7jwqou9.jpeg)

4) You will be prompted to input your passoword. Be sure to input this correctly and note that the password doesn't show while typing. Once finished, hit the return key.

5) A welcome message will be displaced as shown below.

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

Viola!!! We just created and connected to a Linux box. Not as straightforward as a Windows VM, I must say.

As you embark on your Azure adventure, remember that the skills acquired here are just the beginning. With your Linux VM up and running, you're ready to delve into a world of possibilities, from deploying applications and services to optimizing performance and scalability.

Thank you for joining me on this journey of discovery. May your Linux VMs in Azure pave the way for countless achievements and breakthroughs in your cloud endeavors.

Temiloluwa Adediji