There are many reasons to create a Linux Virtual Machine (VM) in Azure; like hosting a web server, database, or many other uses for VMs. It’s extremely easy to create a Linux VM in Azure, in fact you can do it in a matter of a few minute. Then once created, the VM can be connected to via SSH enabling you to configure it for what ever workload you need.
Azure Virtual Machines are the compute capability in Microsoft Azure that enables you to create and host servers in the cloud. This enables an on-demand, scalable cloud-computing resource that just works without worrying about any of the hardware underneath. You are only billed when the VM is running, and you can stop and deallocate the VM if you need to shut it down to suspend billing, and then you can start it back up again to get it running again for use. This makes Azure VMs perfect for everything from continuously running VM workloads (aka “always running”) like you would use for servers, or even remote terminals or task specific VMs that you only need periodically from time to time.
Next, let’s look at creating a Linux VM in Azure so you can get started configuring your workload to run in the cloud!
Create a Linux VM in Azure
There are several Linux distributions made available within Microsoft Azure through the Azure Marketplace. These include Ubuntu, CentOS, RedHat Enterprise Linux (RHEL), and more! For the following steps, we’ll use Ubuntu Server, but go ahead and choose the distro you prefer as you follow along. Let’s go!
- Within the Azure Portal (https://portal.azure.com), click on the + Create a resource button at the top of the Home page.
- On the Create a resource page, search the Azure Marketplace for your favorite Linux distro, then select it. For this article, we’ll search and pick Ubuntu Server.
- On the Azure Marketplace information page for the Linux distro you’ve chosen, click the Create button to get started defining the configuration of the VM to create.
- On the Create a virtual machine page, you will see the Basics tab, and you’ll need to fill out all the required configurations for this new Linux VM. To start, select your Azure Subscription and an existing (or specify to Create new) a Resource group.
The Resource group will be used to organize the multiple Azure resources that are provisioned when the Linux VM is created. You will see later there are several resources created, and using a dedicated Resource group for this VM will keep things well organized in your Azure Subscription.
- For the Instance details section, fill out the specifics that are required for the Linux VM you’re creating. This will include the Virtual machine name that defines the name of the Azure Virtual Machine resource, as well as the Size to specify the vCPU and Memory resources for the VM. The rest of the fields you could leave as the default values to move forward with creation.
Here’s the values that I filled out for these required fields:
Virtual machine name:
(US) East US 2
- For the Administrator account section, fill in the Authentication type that you are going to authenticate with as the admin / root user of the Linux VM once it’s created. For simplicity, I’ll choose Password and enter a Username / password to use.
The SSH public key option for Authentication type is much more secure. For any Production VMs, you’ll want to generate an SSH key pair and use that to setup authentication for the Linux VM. For the simplicity of this article I decided to use Password for now.
- For the Inbound port rules section, ensure that the Select inbound ports setting is set to
SSH (22). This will enable inbound traffic to Port 22 (for SSH) to be allowed on the firewall rules of the Azure Network Security Group that’s configured for the VM once created.
Keep in mind that enabling SSH connections to Port 22 on the Internet is generally a bad idea from a security standpoint. For Production VMs, you’ll want to secure them better than this. But, for this article (and for simple VM usage) this will work for now.
- Finally, we’re ready to click the Review + create button at the bottom of the Create a virtual machine page. This will display a review summary of what you’e going to create, and a green “Validation passed” message will show if there are no errors in the configurations chosen. Then click the Create button to tell Azure to actually go create the Linux VM.
- The deployment of creating the Linux VM in Azure will take a few minutes to complete. While you wait, the portal will display the Deployment progress.
- Once deployment and provisioning has completed, you will see a message saying “Your deployment is complete”, then click Go to resource to navigate to the newly created VM.
- Now that you’ve navigated to the newly created Linux VM on Microsoft Azure, you can view the Public IP address for the VM, then use that IP Address to connect to this VM using SSH. And, if you want to Stop / Deallocate the VM to suspend billing when you don’t need it running, the Stop button is right there too!
Now you have a Linux VM on Azure that you can use for anything you need!
More Advanced VM Configurations and Security
The previous steps guided you through creating a Linux VM on Microsoft Azure using many of the “default” configurations, including the “default” settings for security. When creating Virtual Machines (VMs) in Microsoft Azure for Production use, you’ll definitely want to configure security better so the VM doesn’t get hacked.
To more properly secure Azure Virtual Machines, you’ll want to use one or more of the following features:
- Azure Network Security Group (NSGs) can be used to configure the inbound and outbound firewalls for VMs. You can use this to disable Internet access to SSH (port 22) for the Linux VM so it’s only accessible from the local Virtual Network (VNet), or even so it only allows your specific IP Address to connect.
- Azure Bastion can be used to enable SSH (port 22) access to the Linux VM in Azure right from within the Azure Portal. This is another service to provision and configure, but combining this with NSGs you can secure the VM so it’s not accessible with SSH (or any other port) directly from the Internet.
There are a many other security features in Microsoft Azure, these are just the two most straight forward features to keep in mind. What ever you do, please properly secure your Azure VMs so you don’t get hacked.