Creating and Connecting to Linux Virtual Machine using a Public Key

OLALEKAN john Ayansola - Nov 6 - - Dev Community

Using SSH keys for authentication is a secure and efficient method to access your Linux VM on Azure. By replacing traditional passwords with key-based authentication, you significantly reduce the risk of unauthorized access. Following these steps ensures that your Azure VM is set up with robust security measures right from the start.

This blog will guide you through the detailed steps to create and connect to a Linux VM on Azure, using SSH key-based authentication.

Steps in creating and connecting to a Linux VM on Azure

Setting up a Linux VM on Azure

  • Login to Azure portal

Azure portal

  • Click on the create resources and select virtual machine

create

vm
Create subscription

  • Choose your Azure subscription

subscription

  • Create a Resources Group or select from an existing one

resource group

  • Create a name your Virtual Machine

vm

  • Select the Region you want the Virtual Machine to be deployed

Region

  • Select the availability option according to your need

Availability zone

  • Select Security type

security

  • Select VM architectural

Vm architectural

  • Select the Size of the VM according to the capacity you like to build

VM size

Administrative Account

  • Create the authentication type

authetication

  • Create a username

username

  • Select SSH key type

SSH key type

  • Select the key pair name

key pair name

  • Select inbound ports name

port name

  • Click Review and then create

review and create

  • Validation pass then create

Validation pass

  • Download key after the deployment pass

Downlaod keys

  • Go to resource after the deployment is completed

Go resource

Step 2: Connect to the Azure VM

  • Connect to virtual machine

connect to vm

  • Get the VM IP Address:
    ip address

  • Enter command prompt at the bottom left, then right click the command prompt to run as Administrator

Administation

  • Imput the following commands: ssh -i location/key username@IP Address ‪C:\Users\USER\Downloads\Anuola.pem

command page

  • Enter yes and sudo apt-get -y update to run the update

sudo get update

  • Enter sudo apt-get -y install nginx to install

sudo apt get

  • Then copy the the Ip address to a browser, here you are welcome to linux virtual machine.

Welcome to linux

NOTE
If yours doesn't work you can put http:// before your Ip address and it will work.

CONCLUSION

With this setup, you can confidently manage your VM on Azure, and you may consider adding extra layers of protection, like firewalls, access logging, or configuring network security groups (NSGs) to control traffic. This guide can also be reused or automated for future deployments with tools like Azure CLI or Terraform.
Enjoy working securely in the cloud!

. . .
Terabox Video Player