Unleash The Power of Azure: Creating A Linux VM with SSH keys Security.
Tags: cloudengineering, virtualmachines, vmcreations, azure
Published: 2024-06-02 03:30:27

Hey dev.to community! Ready to level up your cloud game? Today we're diving into Microsoft Azure to create a Linux virtual Machine(VM) with the added security of SSH keys. Ditch those risky passwords and embrace a more secure way to access your cloud resources.

**Why SSH keys on Azure?**

Let's kick things off with a quick rundown of why SSH keys are the way to go for your Azure VMs:

- Fortress-like Security: SSH keys offer solid protection against brute-force attacks, making your VM virtually impenetrable.
- Streamlined Access: Say goodbye to typing passwords every time you log in. SSH keys make connecting to your VM seamless.
- Automation Ace: SSH keys are a delight for automating y=tasks like deployments, updates and maintenance on your VM

**What You'll Need For This Adventure**

- An Azure Account: No account? No problem! Sign up for a free Azure trial to get started.
- Linux Knowledge: Basic familiarity with Linux commands, and Azure portal will make it a breeze.

Let's Build Your Linux Fortress!
**Step 1: log in to Azure portal**
Head over to Azure portal(_https://portal.azure.com/_) and log in with your credentials.

**Step 2: Create a New Virtual Machine**
Just like creating a windows VM from our last post:

- Go to the search box and type "virtual machine" then click.
- On the Virtual machine page, click "Create", under create click on the option "Azure virtual machine"

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

3. Create a Resource group
4. Name your VM (e.g. "MyLinuxVM").
5. Select your region(for optimal performance, choose one close to you).
6. Choose an Availability zone(e.g. Zone 1, 2 or any other option peculiar to you)
7. Leave security type in its default state(Trusted Launch)
8. Under "Image", pick your preferred Linux distribution e.g. Ubuntu.

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

**Step 3: Authentication**

- Under "Authentication Type" select "SSH public key"

**Configure Your VM**
- Choose the VM size that matches your needs, start small; you can always scale up later
- Set up network if needed:; you can leave at default network provided by Azure.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gf2d0rdi5byou058exwv.png)

- Inbound port should be on SSH(22)
_ Leave every other configuration at their default for now as our main focus is creating a VM with Linux OS

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

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

**Step 5: Review and Create**

Give your settings a final check and click "Create". Azure will get to provisioning your Linus VM once your validation is passed.

N:B Validation may not get passed when some of your configurations(Network, image, region, resource and others) are not complete or unsupported by Azure at the moment or by Azure services. Once you get such feedback, you can go back and double check where the error lies, then align.

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

- While Azure is provisioning your Linux VM, copy the prompt on your screen "Download private key and create resource"

Just like the windows VM, your deployment gets complete

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

**Step 6: Connect with your SSH key**
- Click on "Go to resources" select "Connect" then "Native SSH" this opens up instructions on how to connect to your Linux VM, but we shall connect using the CLI or the Powershell.

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

- Open a CLI  or Powershell from your PC
- Type in the following command "ssh -i /path/to/your/private key/ your vmuser@yourvmpublicIP for example: 
                                    
        ssh C:\Users\User\Documents\Mytestubuntu_key.pem azureuser@ 20.75.82.93 press "Enter"

 And Voila! here comes your Linux VM interface


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