Create a Linux virtual machine in Azure
This tutorial guides you through the process of creating a Linux virtual machine (VM) in Azure using the Azure portal. You'll learn how to configure VM settings, select an operating system image, set up networking, and then deploy and connect to your VM.
Step 1: Sign in to the Azure portal
Open your web browser and go to https://portal.azure.com. Sign in with your Azure account credentials.
Step 2: Create a virtual machine
In the Azure portal search bar, type Virtual machines and select it from the results. Then, click + Create and select Virtual machine.
Step 3: Configure basic settings
On the Create a virtual machine page, under the Basics tab, configure the following settings:
- Subscription: Select your Azure subscription.
- Resource group: Click Create new and enter a name for your resource group, for example,
myResourceGroupLinux
. A resource group is a logical container for Azure resources. - Virtual machine name: Enter a unique name for your VM, like
myLinuxVM
. - Region: Choose an Azure region near you or your users, such as
East US
. - Availability options: For this tutorial, you can leave the default No infrastructure redundancy required.
- Security type: Leave as Standard.
- Image: Select a Linux distribution. For this tutorial, choose Ubuntu Server 20.04 LTS - Gen2. You can click See all images to browse other options.
- Size: Select a VM size. For this tutorial, Standard_B1s is a cost-effective option. Click See all sizes to explore more.
- Administrator account:
- Authentication type: Select SSH public key.
- Username: Enter a username for the VM, such as
azureuser
. - SSH public key source: Select Generate new key pair.
- Key pair name: Enter a name for your key pair, like
myKeyPair
. Azure will generate and store this key pair for you. - Inbound port rules:
- Public inbound ports: Select Allow selected ports.
- Select inbound ports: Choose SSH (22).
Step 4: Configure disks
Go to the Disks tab. For this tutorial, you can leave the default settings for OS disk type (e.g., Premium SSD) and Data disks.
Step 5: Configure networking
Go to the Networking tab. You can accept the default settings for virtual network, subnet, and public IP address for this basic setup. The inbound port rule for SSH (port 22) that you configured in the Basics tab will be applied here.
Step 6: Review and create
Navigate to the Review + create tab. Azure will validate your configuration. Once validation passes, review the summary of your VM's settings. If everything looks correct, click Create.
If you chose to generate a new key pair, you will be prompted to download the private key. Download your private key and save it securely. This key is essential for connecting to your VM.
Step 7: Connect to your VM
After the deployment is complete (this may take a few minutes), navigate to your newly created virtual machine resource. On the Overview page, you'll find the VM's public IP address.
Open your SSH client (e.g., PuTTY on Windows, or the built-in SSH client on macOS/Linux) and use the following command, replacing <your-private-key-path>
with the path to your downloaded private key file and <your-public-ip-address>
with the VM's public IP address:
ssh -i <your-private-key-path> azureuser@<your-public-ip-address>
You may be asked to confirm the authenticity of the host. Type yes
and press Enter.
Congratulations! You have successfully created and connected to a Linux virtual machine in Azure.