Quickstart: Create a Linux virtual machine in the Azure portal
Azure virtual machines (VMs) can be created through the Azure portal. The Azure portal is a browser-based user interface to create Azure resources. This quickstart shows you how to use the Azure portal to deploy a Linux virtual machine (VM) running Ubuntu 18.04 LTS. To see your VM in action, you also 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 already have an SSH key pair, you can skip this step.
- Sign in to the Azure portal.
- In the menu at the top of the page, select the
>_icon to open Cloud Shell.
- Make sure the CloudShell says Bash in the upper left. If it says PowerShell, use the drop-down to select Bash and select Confirm to change to the Bash shell.
ssh-keygen -t rsa -b 2048to create the ssh key.
- You will be prompted to enter a file in which to save the key pair. Just press Enter to save in the default location, listed in brackets.
- You will be asked to enter a passphrase. You can type a passphrase for your SSH key or press Enter to continue without a passphrase.
ssh-keygencommand generates public and private keys with the default name of
~/.ssh directory. The command returns the full path to the public key. Use the path to the public key to display its contents with
- Copy the output of this command and save it somewhere to use later in this article. This is your public key and you will need it when configuring your administrator account to log in to your VM.
Sign in to Azure
Sign in to the Azure portal if you haven't already.
Create virtual machine
Type virtual machines in the search.
Under Services, select Virtual machines.
In the Virtual machines page, select Add. The Create a virtual machine page opens.
In the Basics tab, under Project details, make sure the correct subscription is selected and then choose to Create new resource group. Type myResourceGroup for the name.*.
Under Instance details, type myVM for the Virtual machine name, choose East US for your Region, and choose Ubuntu 18.04 LTS for your Image. Leave the other defaults.
Under Administrator account, select SSH public key, type your user name, then paste in your public key. Remove any leading or trailing white space in your public key.
Under Inbound port rules > Public inbound ports, choose Allow selected ports and then select SSH (22) and HTTP (80) from the drop-down.
Leave the remaining defaults and then select the Review + create button at the bottom of the page.
On the Create a virtual machine page, you can see the details about the VM you are about to create. When you are ready, select Create.
It will take a few minutes for your VM to be deployed. When the deployment is finished, move on to the next section.
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 IP address over port 22. In Login using VM local account a connection command is shown. Select the button to copy the command. The following example shows what the SSH connection command looks like:
Using the same bash shell you used to create your SSH key pair (you can reopen the Cloud Shell by selecting
>_again or going to https://shell.azure.com/bash), paste the SSH connection command into the shell to create an SSH session.
Install web server
To see your VM in action, install the NGINX web server. From your SSH session, update your package sources and then install the latest NGINX package.
sudo apt-get -y update sudo apt-get -y install nginx
When done, type
exit to leave the SSH session.
View the web server in action
Use a web browser of your choice to view the default NGINX welcome page. Type the public IP address of the VM as the web address. The public IP address can be found on the VM overview page or as part of the SSH connection string you used earlier.
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.