How to Create a Linux Virtual Machine on Azure (Step-by-Step for Beginners)

작성자

카테고리:

← 피드로
DEV Community · SULIAT · 2026-07-24 개발(SW)
Cover image for How to Create a Linux Virtual Machine on Azure (Step-by-Step for Beginners)

SULIAT

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

  1. Log in to the Azure Portal: Head over to the Azure Portal and sign in.
  2. Search for Virtual Machines: In the search bar at the top, type Virtual Machines and select it. Virtual Machines
  3. Click “+ Create”: This opens the Basics tab, where you’ll configure your new VM. click
  4. Create a Resource Group: On the Basics tab, create a new resource group to keep your resources organized (e.g. MAYRG). basic
  5. 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. Name
  6. Choose a Region: Pick a region that’s geographically close to you for better performance (e.g. Canada Central). region
  7. Availability Zone: Choose No availability option, since this isn’t needed on a free-trial account (no infrastructure redundancy required for learning/testing purposes). Zone
  8. Security Type: Choose Standard. It’s the lowest-tier option and works fine for a free-trial account. type
  9. 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). Image
  10. VM Architecture and Size: Leave both the architecture and size as their default values. VM and Size
  11. Administrator Account: As a first-time user, choose Password instead of SSH Public Key for the authentication type. Public
  12. 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. port
  13. Monitoring Tab: Click on the Monitoring tab and select Disable boot diagnostics. boot
  14. Networking Tab: Click on the Networking tab:
    • Create a new Virtual Network (e.g. MyLinuxVM-VNet)
    • Leave everything else on this tab as default
    • Click OK Virtual Netwrork
  15. Review and Create: Click Review + Create. create

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:

  1. On the VM’s Overview page, look for the **Networking **section, or find the **Public IP **address at the top of the page. Overwiew
  2. 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. Ip address
  3. Click Apply. apply
  4. Click the X to return to the Overview page. close

Step 3: Connect to Your Linux VM

  1. Back on the Overview page, click the Connect button and review the instructions provided there. Connect
  2. Click Check access to confirm you’re ready. check
  3. Look for a green checkmark. Mark
  4. Open a terminal on your computer: Mac: Command + Space (Opens Spotlight Search. Type Terminal and press Return.) terminal
  5. Connect to your Linux VM using SSH: ssh [email protected] linux
  6. Copy this command and paste it into your terminal, then hit Enter. command

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# root 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.
Update

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”.
Install
Hit Enter, and when prompted, type Y to confirm and continue the installation.
Installation

Confirm the Installation

To verify that nginx installed successfully:

  1. Grab your VM’s public IP address. confirm
  2. Paste it into your web browser. web
  3. You should see the default “Welcome to nginx!” page, confirming nginx has been successfully installed on your Linux VM. success

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.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다