This blog post walks us through setting up a Linux virtual machine using Ubuntu Server. While public key authentication is commonly used for SSH access to virtual machines due to its enhanced security, we’ll focus on configuring password-based authentication instead.
We’ll also cover how to prevent unexpected SSH disconnections caused by idle sessions. To ensure uninterrupted access, we’ll adjust the idle timeout settings for your IP address to avoid being logged out unexpectedly.
Additionally, I’ll explain how to optimize costs by disassociating your IP address from the virtual machine when it’s not in use. We’ll also look at how to clean up resources by deleting the resource group containing your virtual machine and its dependencies.
Let’s dive in!
Sign in to the Azure Portal
As a prerequisite, if you don't have an Azure subscription, sign up here to create a free account before we get started. Otherwise, sign in here to access your account.
Create your Virtual Machine
I. In the search bar, type "Virtual Machine" and select "Virtual Machine" from the list of resources shown
II. Click on the "Create" button
III. Select the virtual machine highlighted
IV. You will then be directed to the "Basics" page of the multi-step setup form.
Project Details
In the project details category, there is the subscription and resource group:
I. Subscription
An Azure subscription is essentially a membership that grants you access to Microsoft Azure services. Think of it like signing up for a subscription plan or service. With this subscription, individuals or organizations can take advantage of Azure's wide range of resources and tools, with costs determined by the specific plan you choose. Additionally, Azure provides free and trial options, allowing you to explore its features and experiment before committing to a paid plan.
II. Resource Group
In Azure, a resource group acts like a container or folder, allowing you to organize and manage various resources, such as virtual machines and databases, within the Azure cloud environment.
In the how-to guide, select your resource group or click on "Create new" to create a new resource group.
Instance Details
I. Assign a Name to Your Virtual Machine
II. Select a Region
Choose the geographical location where you want your virtual machine to be hosted.
A region is a specific geographical location with data centres hosting infrastructure and services. Each region operates independently and is designed to be self-contained, with its own set of resources and infrastructure.
III. Choose Availability Options and Zones
Use the drop-down menu to select the desired availability option and availability zone.
In Azure, a region typically includes up to three availability zones, labeled Zone 1, Zone 2, and Zone 3. Each zone contains one or more data centres located several kilometres apart to ensure redundancy.
These data centres operate independently, with separate power, networking, and cooling systems to minimize the risk of disruptions or failures. They are interconnected using fibre optic cables, enabling high-speed data transfer over long distances with minimal latency and high bandwidth performance.
IV. Select your security type from the drop-down
V. 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 to set up a computer with a specific operating system and software.
VI. 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.
Administrator Account
I. 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 attacks, making it a preferred choice for secure remote connections.
However, for this demo, we will use the password option.
II. Type your username and your password.
Inbound Port Rules
I. In this category, select SSH (22) as your inbound port to connect to the Linux server.
II. Click "Next: Disk>" to direct you to the disk page of the setup form
Disk
I. On the Disk page, click on the OS disk type dropdown and select Premium SSD or any disk type of your choice as shown below. Leave the other columns as default.
II. Leave the networking, management, monitoring, and advanced pages of the multi setup form as default. Skip to the Tag page.
Tag
I. 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.
II. Next, click on Review+create
III. Review the summary of your virtual machine configuration and click on the "Create" button to begin the deployment process
IV. Once the deployment is complete, click on "Go to resource."
Connect To Your Virtual Machine
I. Click on the connect button to SSH to your Virtual Machine
II. On the SSH instruction page, copy the command in the blue box and delete the command in the red box. This will give you:
ssh username@ipaddress
III. Open PowerShell/Terminal on your Laptop and input the command, Press enter
IV. You would be asked if you want to continue connecting, type "yes" and press enter
V. At this stage, my connection has timed out because running the command took me a while. If you got this, the next thing to do is to go back to the Azure portal and locate your virtual machine
VI. On the overview page, click on your IP address.
VII. Click on Configuration, increase the idle timeout to 30 minutes, and save.
VIII. Go back to your Powershell/Terminal and input the ssh username@ip, and press enter.
NOTE: If your connection did not time out, once you type yes and press enter, it will request 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
How to Disassociate IP Address
Situations may arise where you need to save costs running your virtual machine. One way to optimise cost is to disassociate your IP address from your virtual machine.
I. Click on your IP address
II. Click on the overview button. On the overview page, click on dissociate at the top-right of the page.
III. It will ask you to confirm dissociation, click "Yes'. Once you click yes, your IP address will be dissociated from your Virtual Machine.
How to Associate IP Address
I. To associate your IP, simply click on the Associate button.
II. A page will open up, choose the Resource type as Network interface. Select your IP address and click on OK.
III. Your IP will be associated back to your virtual machine.