Mastering Azure: Deploying a Linux Virtual Machine and Connecting via SSH
Published: 2023-08-21 22:41:01

Azure, Microsoft's cloud platform, offers a diverse ecosystem that includes robust support for Linux virtual machines (VMs). In this step-by-step guide, we'll explore how to deploy a Linux VM in Azure and connect to it using SSH, making it a breeze to harness the power of Linux in the cloud.

## Prerequisites

Before we embark on our Azure Linux VM journey, make sure you have the following essentials:

Azure Account: You'll need an Azure account to access the Azure portal. If you don't have one, you can sign up for a free trial.

SSH Client: Ensure you have an SSH client installed on your local machine. On Windows, you can use tools like PuTTY or the built-in OpenSSH client. On macOS and Linux, the OpenSSH client is pre-installed.

## Step 1: Sign in to Azure Portal

Start by logging in to the Azure portal using your Azure account credentials.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezbqohzo8pq1kjw88pil.png)

## Step 2: Create a Linux Virtual Machine

In the Azure portal, click on "Create a resource."

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sjrdsd6oivsrmeedkd3c.png)

Search for "Ubuntu Server" or your preferred Linux distribution in the marketplace. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bud4pe6faxlitkk4k73t.png)
Select the version you want and click "Create."

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t6p6tv0fwegqtl1bqb2r.png)

In the "Basics" tab of the virtual machine creation wizard, provide the following details:

Subscription: Choose your Azure subscription.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqs6t25lsvncekbytp7e.png)
Resource group: Create a new one or use an existing group.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ynprji5v6rxfj0bl7diy.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1vz4quo0c75xlfmoflaq.png)

Virtual machine name: Give your VM a unique name.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vjz2yejf0rlmxqjt4k9c.png)

Region: Select the Azure region where your VM will be hosted.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8obztv07ec59p0ingua.png)

Image: Choose the Linux distribution and version.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a41qe764xt4ag4ytmnk4.png)

Size: Pick an appropriate VM size based on your needs.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9lzg4asuwbt07piqet7.png)
In the "Administrator account" section, provide a username and secure password for your VM's administrator account. Alternatively, you can use SSH keys for authentication but here we use username and password.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w8ktw96mrb5c8qp7r4nx.png)

In the "Inbound port rules" section, ensure that "SSH (22)" is allowed for connecting via SSH.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q6vqnfu8trruj1344m98.png)

Review your settings and click "Next."

Complete the remaining steps (disks, networking, management, and advanced) based on your requirements. You can typically accept the default settings for a basic VM setup, click "Review + Create.".

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kgbsi98d8ac0ku962i5g.png)

Review your configuration, and click "Create" to provision your VM.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84hm8nf6ielr3minvdr5.png)

## Step 3: Connect via SSH

After Azure deploys your VM, navigate to your VM's details in the Azure portal.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c8lyumatqnd8idskfyri.png)

Click on "Connect" under the Settings blade.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hrvntbfn7o7g03b5irys.png)

Under the "Connect" menu, you'll find instructions for connecting to your VM. It should look something like this:

shell
Copy code
ssh username@your-vm-ip-address
Replace username with your VM's username and your-vm-ip-address with the VM's public IP address.

Open your terminal or SSH client and paste the SSH command. Press Enter.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7kcza8syr692bw2gttja.png)
You'll be prompted to enter the password for the user you specified during VM creation. If you're using SSH keys, you may be prompted for the passphrase associated with the private key but here we use password.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmltvbo26ecgbmbyman2.png)
Voilà! You're now connected to your Linux VM in Azure. You can start using it just like a local Linux machine.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/axdkcm8yu2s9j0pr1yuu.png)

From here, you can manage your Azure Linux VM as needed. You can install software, configure services, and host web applications, all within your Azure environment.

Conclusion
Deploying a Linux VM in Azure and connecting to it via SSH is a valuable skill for developers, sysadmins, and anyone working in the cloud. It empowers you to leverage Azure's infrastructure while harnessing the capabilities of Linux. Whether you're running web servers, databases, or development environments, Azure offers a robust platform for all your Linux needs. So go ahead, explore, experiment, and make the most of Azure's Linux-friendly ecosystem!