How to Create a Linux Virtual Machine on Azure (Step-by-Step for Beginners)
What is a Virtual Machine? A Virtual Machine (VM) is essentially a computer that lives in the cloud instead of on your desk. A great way to understand why VMs matter is to think about a banking app. Almost everyone has a bank app on their phone. If a bank tried to host that application on its own premises or in its own private data center, it would need to pay for cooling, electricity, hardware maintenance, and a dozen other operational expenses. That gets expensive fast and it doesn't scale well. Instead, banks (and most companies today) use Infrastructure as a Service (IaaS), which gives them full control over a virtual machine without the overhead of owning and maintaining physical hardware. In this article, we'll walk through creating your own Linux VM on Microsoft Azure, step by step.
Step 1: Create the Linux VM
- Log in to the Azure Portal: Head over to the Azure Portal and sign in.
- Search for Virtual Machines: In the search bar at the top, type
Virtual Machinesand select it. - Click "+ Create": This opens the Basics tab, where you'll configure your new VM.
- Create a Resource Group: On the Basics tab, create a new resource group to keep your resources organized (e.g.
MAYRG). - Name Your Virtual Machine: Under Instance Details, give your VM a name. Just like your physical laptop has a name (MacBook, ThinkPad, etc.), your cloud machine needs one too.
- Choose a Region: Pick a region that's geographically close to you for better performance (e.g. Canada Central).
- Availability Zone: Choose
No availabilityoption, since this isn't needed on a free-trial account (no infrastructure redundancy required for learning/testing purposes). - Security Type: Choose
Standard. It's the lowest-tier option and works fine for a free-trial account. - Choose Your Image: The "Image" is essentially the operating system theme for your VM. Since we're creating a Linux VM, choose
Ubuntu(any available version works). - VM Architecture and Size: Leave both the architecture and size as their default values.
- Administrator Account: As a first-time user, choose
Passwordinstead ofSSH Public Keyfor the authentication type. - Inbound Port Rules: Click
Allow selected ports, then select:SSH (22)- enabled by default, needed to connect to your VM.HTTP (80)- enable this if you plan to install and serve anything on the VM.
- Monitoring Tab: Click on the
Monitoringtab and selectDisable boot diagnostics. - Networking Tab: Click on the
Networkingtab:- Create a new Virtual Network (e.g.
MyLinuxVM-VNet). - Leave everything else on this tab as default.
- Click
OK.
- Create a new Virtual Network (e.g.
- Review and Create: Click
Review + Create. Once validation passes, clickCreate. Azure will now deploy your virtual machine. Once it's done, clickGo to resourceto open your new VM's Overview page.
Note: "Go to resource" simply means navigating to the thing you just created.
Step 2: Configure Idle Timeout (Important!)
When you create a VM, there's a setting that's easy to miss but can cause a lot of headaches if skipped: the idle timeout. If you don't configure this, you might be working in your terminal and suddenly without warning your session disconnects, leaving you wondering what went wrong. Here's how to fix it:
- On the VM's Overview page, look for the Networking section, or find the Public IP address at the top of the page.
- Click on the IP address.
- Find the idle timeout setting and drag it from the default 4 minutes up to the maximum of 30 minutes.
- Click
Apply. - Click the
Xto return to the Overview page.
Step 3: Connect to Your Linux VM
Back on the Overview page, click the Connect button and review the instructions provided there. Click Check access to confirm you're ready. Look for a green checkmark.
Open a terminal on your computer:
- Mac:
Command + Space(Opens Spotlight Search. TypeTerminaland pressReturn.)
Connect to your Linux VM using SSH:
ssh azureuser@20.63.81.178
Copy this command and paste it into your terminal, then hit Enter. You'll be prompted with: "Are you sure you want to continue connecting?" - type yes and hit Enter. Next, you'll be prompted for a password. Enter the password you set earlier and hit Enter.
Heads up: When typing your password, nothing will appear on the screen; no dots, no asterisks. It's not broken, it's just invisible for security reasons. Type carefully and confidently, then hit Enter.
Once connected, your terminal prompt will change to something like:
azureuser@MylinuxVm:~$
This confirms you've successfully connected to the Linux VM you created.
Step 4: Log In as Root
After connecting, the next thing to do is switch to root. What is root? Root is the superuser account on Linux, the one account that has full admin access to everything on the system. If you want to update or install anything on your VM, you need to be operating as root.
Log in as root for the whole session: Type sudo su. su stands for "super user." After running this and hitting Enter, your prompt will change to something like:
root@MylinuxVm:/home/azureuser#
This confirms you're now operating as root.
Step 5: Update the Package Index
Before installing anything, it's good practice to update the package index. This checks whether everything on your VM is running the latest available version. Type:
apt update
Hit Enter. This command updates your Linux VM's package list to the latest version available, ensuring you install up-to-date software in the next step.
Step 6: Install Something on the Linux VM (Example: nginx)
Now that your package index is up to date, let's install a package - in this example, nginx, a popular web server. apt is the package manager for Linux, so we'll use it to install nginx: type this command in the terminal:
apt install nginx
Hit Enter, and when prompted, type Y to confirm and continue the installation.
Confirm the Installation
To verify that nginx installed successfully:
- Grab your VM's public IP address.
- Paste it into your web browser.
You should see the default "Welcome to nginx!" page, confirming nginx has been successfully installed on your Linux VM.
Wrapping Up
That's it, you've successfully provisioned a Linux VM on Azure, secured your session from unexpected timeouts, connected to it via SSH, switched to root, updated the package index, and installed your first package (nginx). From here, you can keep exploring, host applications, experiment with server administration, or install anything else you need, all without touching physical hardware. Happy building.
Comments
No comments yet. Start the discussion.