Quickstart: Create a Linux virtual machine in the Azure portal
Azure virtual machines (VMs) can be created through the Azure portal. This method provides a browser-based user interface to create VMs and their associated resources. This quickstart shows you how to use the Azure portal to deploy a Linux virtual machine (VM) in Azure that runs Ubuntu. To see your VM in action, you then SSH to the VM and install the NGINX web server.
If you don't have an Azure subscription, create a free account before you begin.
Create SSH key pair
You need an SSH key pair to complete this quickstart. If you have an existing SSH key pair, this step can be skipped.
To create an SSH key pair and log into Linux VMs, run the following command from a Bash shell and follow the on-screen directions. For example, you can use the Azure Cloud Shell or the Windows Substem for Linux. The command output includes the file name of the public key file. Copy the contents of the public key file (
cat ~/.ssh/id_rsa.pub) to the clipboard:
ssh-keygen -t rsa -b 2048
For more detailed information on how to create SSH key pairs, including the use of PuTTy, see How to use SSH keys with Windows.
Log in to Azure
Log in to the Azure portal at http://portal.azure.com
Create virtual machine
Choose Create a resource in the upper left-hand corner of the Azure portal.
In the search box above the list of Azure Marketplace resources, search for and select Ubuntu Server 16.04 LTS by Canonical, then choose Create.
Provide a VM name, such as myVM, leave the disk type as SSD, then provide a username, such as azureuser.
. For Authentication type, select SSH public key, then paste your public key into the text box. Take care to remove any leading or trailing white space in your public key.
Choose to Create new resource group, then provide a name, such as myResourceGroup. Choose your desired Location, then select OK.
Select a size for the VM. You can filter by Compute type or Disk type, for example. A suggested VM size is D2s_v3.
Under Settings, leave the defaults and select OK.
On the summary page, select Create to start the VM deployment.
The VM is pinned to the Azure portal dashboard. Once the deployment has completed, the VM summary automatically opens.
Connect to virtual machine
Create an SSH connection with the VM.
Select the Connect button on the overview page for your VM.
In the Connect to virtual machine page, keep the default options to connect by DNS name over port 22. In Login using VM local account a connection command is shown. Click the button to copy the command. The following example shows what the SSH connection command looks like:
Paste the SSH connection command into a shell, such as the Azure Cloud Shell or Bash on Ubuntu on Windows to create the connection.
Install web server
To see your VM in action, install the NGINX web server. To update package sources and install the latest NGINX package, run the following commands from your SSH session:
# update packages sudo apt-get -y update # install NGINX sudo apt-get -y install nginx
exit the SSH session and return to the VM properties in the Azure portal.
Open port 80 for web traffic
A Network Security Group (NSG) secures inbound and outbound traffic. When a VM is created from the Azure portal, an inbound rule is created on port 22 for SSH connections. Because this VM hosts a web server, an NSG rule needs to be created for port 80.
- On the VM overview page, select Networking.
- The list of existing inbound and outbound rules are shown. Choose to Add inbound port rule.
- Select the Basic option across the top, then choose HTTP from the list of available services. Port 80, a priority, and name, are provided for you.
- To create the rule, select Add.
View the web server in action
With NGINX installed and port 80 open to your VM, the web server can now be accessed from the internet. Open a web browser, and enter the public IP address of the VM. The public IP address can be found on the VM overview page, or at the top of the Networking page where you add the inbound port rule.
Clean up resources
When no longer needed, you can delete the resource group, virtual machine, and all related resources. To do so, select the resource group for the virtual machine, select Delete, then confirm the name of the resource group to delete.
In this quickstart, you deployed a simple virtual machine, created a Network Security Group and rule, and installed a basic web server. To learn more about Azure virtual machines, continue to the tutorial for Linux VMs.