Step-By-Step: How To Create a Linux Virtual Machine In Azure
Tags: linux, webdev, vm
Published: 2024-04-10 12:31:01

_Ubuntu_ is a free and easy to install flavor of the Linux operating system, and it’s for desktops and servers. A lot of technologies used for the web, data science and software development are designed for Linux. You can run them using command-line. I’ve used Ubuntu when creating and hosting web pages, setting up SQL databases and Elasticsearch clusters, and managing containers with Docker.
In this blog post, we will explore the steps involved in setting up a Linux virtual machine using Ubuntu Server. By default, SSH access to virtual machines often relies on public key authentication for enhanced security. However, in this blog, we will use password-based authentication preferably.

We will also demonstrate how to prevent unexpected SSH disconnections due to idle sessions, it's important to extend the idle timeout for your IP address to prevent unexpected logouts.

Also, apart from deleting your resource group that houses your virtual machine and its dependents, I will show you how you can disassociate your IP address from the virtual machine when not in use to ensure cost optimization.

Let's get Started!!



**SIGN IN TO AZURE PORTAL**

As a prerequisite, If you don't have an Azure subscription, [log in here](https://azure.microsoft.com/en-us/free/search/?ef_id=_k_CjwKCAjwjYKjBhB5EiwAiFdSfqO5RuP-vd3LDCdpQGJWRrVpBNjV55OtxhxpjeU7eFCRwp5gjMqslhoCAOQQAvD_BwE_k_&OCID=AIDcmmfdukp5kz_SEM__k_CjwKCAjwjYKjBhB5EiwAiFdSfqO5RuP-vd3LDCdpQGJWRrVpBNjV55OtxhxpjeU7eFCRwp5gjMqslhoCAOQQAvD_BwE_k_&gclid=CjwKCAjwjYKjBhB5EiwAiFdSfqO5RuP-vd3LDCdpQGJWRrVpBNjV55OtxhxpjeU7eFCRwp5gjMqslhoCAOQQAvD_BwE) to create a free account before we get started. Now that you have created your Azure subscription, sign in to the [Azure portal ](https://portal.azure.com/)using your mail and password to get started.

**CREATE YOUR VIRTUAL MACHINE**

a. In the search bar, type "Virtual Machine"

b. From the search results, select "Virtual Machine" from the list of resources shown

c. Click on the "Create" button

d.) Select the virtual machine highlighted



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

e)You will be directed to the "Basics" page.



**Project Details**

In the project details category, we have the subscription and resource group;

a) **Subscription**

An Azure subscription in simple terms means a membership or access pass to use Microsoft Azure. It's similar to subscribing to a service or signing up for a subscription plan. With an Azure subscription, individuals or organizations can use and benefit from the various services and resources provided by Azure at a cost depending on your type of subscription. However, it also offers free and trial options, giving you a chance to explore and experiment with Azure before committing to a paid subscription.

b)**Resource Group**

A resource group in Azure is like a container or folder that helps you organize and manage the different resources such as virtual machines and databases that you use in the Azure cloud.

Imagine you have a room with different items scattered all over the place. It becomes challenging to find what you need when everything is upside down. In this scenario, the room represents your Azure cloud environment, and the resources are the items in the room. Now, imagine you decide to tidy up and arrange your items where they are initially meant to be. Each compartment keeps related items organized and makes it easier to find what you need.

In the how-to guide, select your resource group or click on "Create new" to create a new resource group.


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


**Instance Details**

a) Give your virtual machine a name

b) In the region section, select the location you want your virtual machine to be.

A region refers to a specific geographical location with data centers that host infrastructure and services. Each region operates independently and is designed to be self-contained, with its own set of resources and infrastructure.

c) Next, click on the drop-down to select your availability option and availability Zone.

In Azure, a region can consist of three availability zones, known as Zone 1, Zone 2 and Zone 3. Each zone has one or more data centers that are kilometers apart from each other.

These data centers are equipped with independent power, networking, and cooling infrastructure to minimize the impact of failures and disruptions. What physically Links these data centers together is Fibre Optic Cable. Fiber optic technology allows for high-speed data transmission over long distances while maintaining low latency and high bandwidth capabilities.


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

d) Select your security type from the drop-down

e) In the image section, select any Ubuntu Server.

Ubuntu is a Linux Operating System. An image is an operating system. It's like a blueprint for creating virtual machines or computer systems. It has all the instructions and settings needed to set up a computer with a specific operating system and software.

f) Select the size of your virtual machine from the drop-down or click on "See all sizes". Leave the other information in its default state.

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


**Administrator Account**

a) Select the password authentication type.

Password-based authentication involves using a username and secret password to access a system as shown below.

While SSH public key authentication relies on key pairs and cryptographic algorithms for secure remote access. Public key authentication offers stronger security and protection against various attacks, making it a preferred choice for secure remote connections.

However, for the purpose of this demo, we will use Password.

b) Type your username and your password.


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


**Inbound Port Rules**

a) In this category, select SSH (22) as your inbound port to connect to the Linux server.

b) Click "Next: Disk>" to direct you to the disk page

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


**Disk**

a) On the Disk page click on the OS disk type drop-down and select Premium SSD or any disk type of your choice as shown below. Leave the other columns as default.

b) Leave the networking, management, monitoring and advanced pages as default. Skip to the Tag page.


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

**Tag**

a) Give your tag a name

Tags are a way to label and organize resources in cloud computing environments. The purpose of tags is to provide metadata or additional information that helps in managing, organizing, and tracking resources within a cloud infrastructure.

b) Next, click on Review+create

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

c) Review the summary of your virtual machine configuration and click on the "Create" button to begin the deployment process


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

d)Once the deployment is complete, click on "Go to resource".


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


**CONNECT TO YOUR VIRTUAL MACHINE**

a) Click on the connect button to SSH to your Virtual Machine

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


b) Scroll down to No 4, Copy the command in the red box and delete the command in the blue box. This will give you:

**ssh username@ipaddress**


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

c) Open PowerShell on your Laptop and input the command, Press enter

d) You would be asked if you want to continue connecting, type "yes" and press enter


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

e)At this stage, my connection has closed because it took me a while to run the command. If you got this, the next thing to do is to go back to Azure portal and locate your virtual machine.


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

f)On the overview page, click on your IP address.


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

g) Click on Configuration and increase the idle timeout to 30 minutes. Once you are done, ensure to save it.


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

h) Go back to your Powershell and input the ssh username@ip, press enter.

_NOTE: If your connection did not time out/close, once you type yes and press enter, it would ask that you input your password._

i) Now input your password and press enter.

j) Once you press enter, you would be logged in to your virtual machine as shown below.


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

How To Disassociate IP Address

Situations may arise where you need to save cost running your virtual machine.One way to optimise cost is to disassociate your IP address from your virtual machine.

a) Click on your IP address


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

b) Click on the Overview.

c) On the overview page, click on dissociate at the top-right of the page.


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

d) It will ask you to confirm dissociation, click "Yes'. Once you click yes, your IP address will be dissociated from your Virtual Machine.


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

**How To Associate IP Address**

a)To associate your IP, simply click on the Associate button.

b) A page will open up, choose the Resource type as Network interface. Select your IP address and click on OK.

c) Your IP will be associated back to your virtual machine.


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