Deploy a Linux VM and Web Server

Launch an Ubuntu VM in Azure and serve a live web page with NGINX.

Introduction

30 Second Summary

Every website you visit lives on a server somewhere in the world. Learning to create and manage these servers in the cloud is the foundation of nearly every cloud engineering role.

In this project, you will launch a Linux virtual machine in Microsoft Azure, connect to it securely over SSH, and install a web server that serves a live page anyone in the world can visit.

What You'll Build

You will create an Ubuntu Linux virtual machine in Azure, connect to it via SSH, and deploy an NGINX web server accessible from any browser.

By the end of this project, you'll have:

  • A running Linux virtual machine deployed in Azure's cloud, organized within a resource group.
  • A secure SSH connection from your local terminal to your remote server using a key pair.
  • A live NGINX web server serving a page on the public internet via your VM's public IP address.
  • Secret Mission: Customize your NGINX welcome page with your own HTML content.

Are there any prerequisites?

You will need a credit or debit card to verify your Azure free account. No charges will be made. Azure gives you $200 in credit for 30 days, plus 750 free hours per month of the VM size used in this project for 12 months.

Create Your Azure Free Account

Before you can launch a virtual machine in the cloud, you need access to a cloud platform.

In this step, you will create a free Azure account, sign in to the Azure Portal, and confirm your local machine has an SSH client ready to go.

In this step, get ready to:
  • Create a free Azure account with $200 credit.
  • Sign in to the Azure Portal and confirm it loads.
  • Verify your SSH client is installed and working.
Sign up for Azure free

Azure offers a free tier that includes $200 credit for your first 30 days and 12 months of free services. This means your virtual machine will cost nothing to run during this project.

  • Open your browser and go to azure.microsoft.com/en-us/free.
  • Click Start free.
  • Sign in with your Microsoft account, or create a new one if you do not have one.
  • Verify your identity with a phone number when prompted.
  • Enter a credit or debit card for verification.

Will I be charged?

No. Azure requires a card for identity verification only. You will not be charged during this project.

The free tier includes 750 hours per month of B1s virtual machines for 12 months. That is enough to run one VM around the clock for an entire month.

Sign in to the Azure Portal

The Azure Portal is the web-based dashboard where you will create and manage all your cloud resources.

  • Once your account is created, go to portal.azure.com.
  • Sign in with the same Microsoft account you just used.
  • Confirm you can see the portal home page with the search bar at the top.

Can't sign in to the portal?

Make sure you are using the same email address you registered with. If you created a new Microsoft account, check your inbox for a verification email you may need to confirm first.

Help me troubleshoot my Azure Portal sign-in issue.

Verify your SSH client is available

You will use SSH to connect to your virtual machine remotely. Linux has an SSH client built in, so you just need to confirm it is available.

  • Press the Super key (or Ctrl+Alt+T) to open your terminal.
  • Check your SSH client version by running this command:
ssh -V

✔️ I see a version number

You should see output like OpenSSH_8.9p1 or similar. Your SSH client is ready to go.

ⓧ Command not found

If you do not see a version number, install the SSH client by running this command:

sudo apt install openssh-client
  • Enter your system password when prompted.
  • After the installation completes, run ssh -V again to confirm it works.

What is SSH?

SSH (Secure Shell) is a protocol that lets you securely connect to a remote computer over the internet. You will use it to log in to your Azure virtual machine and run commands on it, just as if you were sitting in front of it.

Your account is ready and your tools are in place. Next up, you will create your Linux virtual machine in Azure.

Create Your Linux Virtual Machine

You have an Azure account ready to go. Now it's time to create the actual server that will host your web page.

A virtual machine is a computer that runs in the cloud instead of sitting on your desk. In this step, you'll configure and deploy an Ubuntu Linux VM in Azure, complete with the security settings needed to connect to it later.

In this step, get ready to:
  • Create a resource group to organize your Azure resources.
  • Configure and deploy an Ubuntu Linux virtual machine.
  • Download your SSH private key for secure access.
Configure your VM's project and instance details

Every Azure resource lives inside a resource group. Think of it as a folder that keeps related resources together so you can manage or delete them as a set.

  • In the Azure Portal, click the search bar at the top of the page.
  • Type Virtual machines and select Virtual machines under Services.
  • Click Create.
  • Select Virtual machine from the dropdown.

You should now see the "Create a virtual machine" form. Under Project details:

  • Select your subscription from the Subscription dropdown (it should already be selected).
  • Under Resource group, click Create new.
  • Enter myResourceGroup as the name and click OK.

Now scroll down to Instance details:

  • Set Virtual machine name to myVM.
  • Set Security type to Standard.
  • Set Image to Ubuntu Server 22.04 LTS - Gen2.
  • Set Size to Standard_B1s. This is free tier eligible.

What is Standard_B1s?

The B1s is a burstable VM size that Azure includes in its free tier. You get 750 hours per month of B1s usage free for 12 months. That's enough to run one VM around the clock for an entire month without being charged.

Don't see Standard_B1s in the size list?

Click See all sizes to expand the full list. You can search for B1s in the search box. If the size is unavailable in your selected region, try changing the Region dropdown to a different location.

help me find the Standard_B1s VM size in Azure

Set up SSH authentication

An SSH key pair is a pair of files used to prove your identity when connecting to a remote server. Azure will generate the pair for you and give you the private key to download.

Scroll down to the Administrator account section on the same page:

  • Set Authentication type to SSH public key.
  • Set Username to azureuser.
  • Set SSH public key source to Generate new key pair.
  • Enter myKey as the Key pair name.

Why SSH keys instead of a password?

SSH keys are far more secure than passwords. A key pair uses cryptography to verify your identity without ever sending a secret over the network. This is the standard way to access cloud servers in production.

Open inbound ports and deploy your VM

By default, Azure blocks all incoming traffic to your VM. You need to open specific ports so you can connect via SSH and serve web traffic later.

Scroll down to the Inbound port rules section:

  • Set Public inbound ports to Allow selected ports.
  • In the Select inbound ports dropdown, select both SSH (22) and HTTP (80).

What are ports 22 and 80?

Port 22 is used by SSH to let you connect to the server's command line remotely. Port 80 is used by HTTP to serve web pages to browsers. Without these ports open, no one could reach your VM.

Now deploy the VM:

  • Click Review + create at the bottom of the page.
  • Review your settings, then click Create.
  • A "Generate new key pair" window will appear. Click Download private key and create resource.
  • Your browser downloads a file called myKey.pem. Note where it saves (usually your ~/Downloads folder).
  • Wait for the deployment to complete. This takes 1-2 minutes.
  • Once deployment finishes, click Go to resource.

You should now see your VM's overview page in the Azure Portal. It shows the status as "Running" and displays a public IP address.

Deployment failed or validation errors?

If you see a validation error, scroll up to check for red error messages. Common causes include selecting a VM size that is not available in your region, or a resource group name that already exists.

If the deployment itself fails, try selecting a different region from the Region dropdown and deploying again.

help me troubleshoot my Azure VM deployment

Your Linux VM is live in the cloud. Next up, you'll connect to it from your local terminal using SSH and the key file you just downloaded.

Connect to Your VM via SSH

Your virtual machine is running in Azure, but right now it is just a remote computer you cannot interact with. To configure it as a web server, you need a way to send commands to it from your local terminal.

SSH (Secure Shell) is the standard protocol for connecting to remote Linux servers. It encrypts everything between your machine and the VM, so your commands and data travel securely. You will use the private key file you downloaded in the previous step to authenticate.

In this step, get ready to:
  • Copy your VM's public IP address from the Azure Portal.
  • Set secure permissions on your SSH key file.
  • Establish an SSH connection to your remote Ubuntu server.
Copy your VM's public IP address

Every VM in Azure gets a public IP address that acts as its address on the internet. You need this IP to tell SSH where to connect.

  • In the Azure Portal, you should already be on your VM's overview page (if not, search Virtual machines in the top search bar, then click myVM).
  • Find the Public IP address field in the Essentials section near the top of the overview page.
  • Click the copy icon next to the IP address, or select the IP and copy it manually.
  • Paste it somewhere handy (a text file or sticky note) so you can use it in the next substep.

What does a public IP address look like?

It is a set of four numbers separated by dots, like 20.84.53.127. Your specific IP will be different from everyone else's.

Set permissions on your SSH key file

SSH refuses to use a private key file if other users on your system can read it. You need to restrict the file permissions before SSH will accept it.

  • Open your terminal.
  • Set the correct permissions on your key file by running this command:
chmod 400 ~/Downloads/myKey.pem

What does this command do?

chmod 400 sets the file so only you (the owner) can read it, and nobody else on the system can read, write, or execute it. SSH requires this level of restriction on private key files to prevent accidental exposure.

  • Verify the permissions were set by running:
ls -l ~/Downloads/myKey.pem

You should see -r-------- at the beginning of the output, confirming the file is read-only for you.

Seeing 'No such file or directory'?

Your key file may have downloaded to a different location. Check your browser's default download folder. If the file is somewhere else, update the path in the command to match where it actually is.

Help me find my downloaded myKey.pem file

Connect to your VM via SSH
  • Connect to your VM by running this command (replace the IP address with the one you copied):
ssh -i ~/Downloads/myKey.pem azureuser@[[VM_PUBLIC_IP="your VM's public IP address"]]

What does this command do?

  • ssh starts a secure shell connection to a remote server.
  • -i ~/Downloads/myKey.pem tells SSH to authenticate using your private key file instead of a password.
  • azureuser@ is the username you configured when creating the VM.
  • The IP address at the end is where SSH connects to.

SSH will ask you: Are you sure you want to continue connecting (yes/no)?

  • Type yes and press Enter.

Why does SSH ask this?

The first time you connect to any server, SSH asks you to confirm its identity. This is a security measure to prevent connecting to an imposter server. You only see this prompt once per server.

You should now see a terminal prompt that looks something like azureuser@myVM:~$. This means you are logged into your remote Ubuntu server in the cloud.

Connection timed out or refused?

Make sure you copied the correct public IP address from the VM overview page. Double-check that the VM is in the Running state (visible at the top of the overview page).

If you see a "Permission denied" error, confirm you ran the chmod 400 command on the correct file path and that the username is azureuser.

Help me troubleshoot my SSH connection to Azure

You are now logged into a Linux server running in the cloud. Next up, you will install a web server on it and make a live web page accessible to anyone on the internet.

Install NGINX and View Your Live Web Page

You've successfully connected to your cloud VM over SSH. Now it's time to put that server to work by turning it into a live web server.

NGINX is a lightweight, high-performance web server used by millions of websites. You'll install it on your VM and instantly have a live web page accessible from anywhere in the world.

In this step, get ready to:
  • Install the NGINX web server on your VM.
  • Verify your web page is live on the internet.
  • Exit your SSH session and return to your local terminal.
Update packages and install NGINX

Before installing any software on a Linux server, you should update the package list to make sure you get the latest available version.

  • In your SSH session on the VM, update the package list and install NGINX by running this command:
sudo apt-get -y update && sudo apt-get -y install nginx

What does this command do?

  • sudo runs the command with administrator privileges, which is required for installing software.
  • apt-get -y update refreshes the list of available packages so your system knows what's out there.
  • && chains the two commands together. The second command only runs if the first one succeeds.
  • apt-get -y install nginx installs NGINX. The -y flag automatically answers "yes" to any confirmation prompts.

The command takes about 30 seconds to finish. You should see lines scrolling through your terminal as packages download and install.

Seeing "Unable to locate package nginx"?

  • Make sure you are running this command inside your SSH session on the VM, not on your local machine. Your terminal prompt should show azureuser@myVM.
  • If the update step failed due to a network issue, try running sudo apt-get -y update on its own first, then run sudo apt-get -y install nginx separately.

Why can't I install NGINX on my VM?

View your live web page in a browser

NGINX starts automatically after installation. Your VM already has HTTP port 80 open from the network security group you configured earlier. This means your web server is already live.

  • Open a web browser on your local machine (not inside the SSH session).
  • In the address bar, type your VM's public IP address and press Enter. This is the same IP address you copied from the Azure Portal in the previous step.

You should see the "Welcome to nginx!" default page. This confirms your VM is serving web traffic to the entire internet.

What just happened?

When you type your VM's IP address in a browser, the request travels over the internet to your Azure VM. The network security group allows the traffic through on port 80 because you configured that inbound rule during VM creation.

NGINX receives the request and serves back the default HTML page stored at /var/www/html/index.nginx-debian.html. Your browser renders that HTML and you see the welcome page.

Page not loading in your browser?

  • Make sure you are using http:// (not https://) in your browser. NGINX is not configured for HTTPS at this point.
  • Double-check that the IP address matches what the Azure Portal shows on your VM's overview page.
  • Confirm your inbound port rules include HTTP (80). Go to your VM in the Azure Portal, click Networking in the left menu, and verify port 80 is listed as allowed.

Why can't I see the NGINX welcome page in my browser?

Exit your SSH session

Your web server is running independently on the VM. You don't need to stay connected over SSH for it to keep serving pages.

  • Disconnect from your VM by running this command in your SSH session:
exit
  • Your terminal prompt should change back to your local machine's prompt (no longer showing azureuser@myVM).

Your web server keeps running

Closing the SSH session does not shut down your VM or stop NGINX. Your web page remains live and accessible from any browser. You can reconnect via SSH any time using the same command from earlier.

You now have a live web server running in the cloud. Next up, you'll take on a secret mission to customize that default page with your own HTML content.

Secret mission

Customize Your Web Page

You have a live web server, but it is showing the default NGINX page. Replace it with your own custom HTML so the world sees something you created.

Clean Up Your Resources

Clean Up Your Resources

Your VM is running on Azure and counts against your free tier hours (750 hours/month of B1s burstable VMs). Decide whether to keep your resources running, pause them to come back later, or delete them entirely.

Cost warning

If your Azure free tier expires or you exceed 750 hours/month, your VM will start incurring compute charges. If you are not planning to use the VM right away, stop or delete it to avoid unexpected costs.

Resources you used:

  • Resource group (myResourceGroup).
  • Ubuntu Server virtual machine (myVM).
  • SSH private key file (myKey.pem) saved locally.
  • Network security group with SSH and HTTP inbound port rules.
  • Public IP address assigned to your VM.
  • Virtual network and subnet (created automatically with the VM).

Keep everything running

No action needed. Choose this if you are still actively experimenting with your VM or plan to continue building on it.

Your Azure free tier covers one B1s VM running 24/7 for a full month (750 hours). As long as you are within your first 12 months, you will not be charged.

Set up Auto-shutdown as a safety net

  • Go to your VM in the Azure Portal.
  • In the left menu, find Auto-shutdown under the Operations section.
  • Enable it and set a time that works for you.

This automatically shuts down the VM each day, preventing it from running while you sleep or forget about it.

Pause - I'll come back to this later

Stop the VM to free up compute charges while keeping your disk and configuration intact. You can restart it later without recreating anything.

  • Go to your VM (myVM) in the Azure Portal.
  • Click Stop in the top toolbar.
  • Wait for the status to change to Stopped (deallocated).

What does deallocating mean?

Stopping a VM in Azure deallocates the compute resources, which means you are no longer charged for the VM itself. Your disk is preserved so you can restart the VM later with all your files and configurations intact.

Note that a small storage charge for the disk may still apply, but this is typically negligible under the free tier.

Delete - I don't want to use this again

Remove all project resources permanently. This deletes the VM, disk, network, public IP address, and security group in one action.

  • In the Azure Portal, search for Resource groups in the top search bar and select it.
  • Click on myResourceGroup.
  • Click Delete resource group.
  • Type myResourceGroup to confirm, then click Delete.
  • Delete the local key file by running this in your terminal:
rm ~/Downloads/myKey.pem

Nice Work!

Nice Work!

You just launched a Linux server in the cloud and made it serve a live web page to the entire internet.

You've learned how to:

  • Provisioned a Linux virtual machine in Azure and configured a network security group to control inbound traffic.
  • Connected to a remote server over SSH using a key pair for secure authentication.
  • Installed NGINX and verified a live web server accessible from any browser via your VM's public IP address.
  • Customized your NGINX welcome page with your own HTML content served on the public internet.

Ready to quiz yourself?