Creating a Linux Virtual Machine on Azure and Connecting It to Visual Studio Code
Table of contents
This blog will cover the steps to create a Linux Virtual Machine (VM) on Azure and establish a secure connection using Visual Studio Code. This guide showcases my expertise in cloud engineering and DevOps practices.
Why Creating a Linux Virtual Machine on Azure is Important
In today’s cloud-driven world, Linux Virtual Machines (VMs) are at the heart of infrastructure management and software development. As a Cloud Engineer or DevOps professional, mastering the creation and management of Linux VMs on platforms like Azure is a fundamental skill. Here’s why:
Scalability and Flexibility: Azure VMs allow you to scale workloads up or down based on demand, providing the flexibility to meet business needs efficiently.
Development and Testing: Linux VMs are commonly used for developing, testing, and deploying applications in a controlled and secure environment.
Cost-Effectiveness: Azure’s pay-as-you-go model ensures you only pay for the resources you use, making it an economical choice for both individuals and businesses.
Global Reach: Hosting a Linux VM on Azure ensures that your application or service is accessible globally, thanks to Azure’s extensive data centre network.
Skill Validation: Setting up and managing Linux VMs showcases your hands-on expertise with Azure, a crucial requirement for Cloud Engineering and DevOps roles.
1. Prerequisites
Before you begin, ensure you have:
An active Azure subscription (sign up for a free account if needed).
Visual Studio Code installed on your local machine.
Azure CLI installed and configured. refer to my previous blog
SSH Key pair for secure authentication (or generate one during the process).
2. Log in to the Azure Portal
Navigate to Azure Portal.
Sign in with your Azure account credentials.
3. Create a Linux Virtual Machine
Step 1: Navigate to Virtual Machines
From the Azure portal dashboard, search for Virtual Machines in the search bar and select it.
Step 2: Create a New Virtual Machine
Click on + Create and select Virtual Machine.
Step 3: Configure Basic Settings
Fill in the required fields:
Subscription: Select your subscription.
Resource Group: Create a new resource group (e.g.,
MyLinuxVM-RG
) or use an existing one.Virtual Machine Name: Enter a unique name (e.g.,
MyLinuxVM
).Region: Select a region close to your location.
Image: Choose a Linux distribution, e.g., Ubuntu 22.04 LTS.
Size: Select a VM size (e.g., Standard_B1s).
Authentication Type: Select SSH Public Key.
Username: Enter a username for the VM.
SSH Key: Paste your public key or generate a new one.
Step 4: Configure Networking
Under the Networking tab:
Leave the default settings or configure them as needed.
Ensure Allow SSH (22) is enabled.
Step 5: Review and Create
Review all settings under the Review + Create tab.
Click Create to deploy your VM.
4. Connect to the Linux Virtual Machine
Step 1: Retrieve the Public IP Address
Once the VM is deployed, navigate to its overview page.
Copy the Public IP Address of the VM.
Step 2: SSH into the VM
Open a terminal on your local machine.
Run the following command:
ssh username@public-ip-address
OR
ssh -i <generated key pair download address> username@public-ip-address
Replace <username>
with your VM's username and <Public-IP>
with the copied address.
Accept the fingerprint confirmation and enter the VM.
5. Install and Configure Visual Studio Code
Step 1: Install the Remote Development Extension Pack
Open Visual Studio Code.
Navigate to the Extensions view (Ctrl+Shift+X
).
Search for and install the Remote Development Extension Pack.
Step 2: Connect to the VM
Press F1
or Ctrl+Shift+P
to open the Command Palette.
Type Remote-SSH: Connect to Host and select it.
Enter the SSH connection string:
<username>@<Public-IP>
Select the default SSH configuration file and connect.
6. Verify Connection and Start Development
Once connected, Visual Studio Code will open the remote workspace.
Verify by checking the terminal within VS Code or exploring the file structure.
7. Clean Up Resources
To avoid incurring costs, delete the resource group created for this VM:
Go to Resource Groups in the Azure portal.
Select your resource group and click Delete Resource Group.
Confirm the deletion.
Conclusion
Following this guide, you have successfully created a Linux Virtual Machine on Azure, established an SSH connection, and integrated it with Visual Studio Code for development.