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
- Click on the create resources and select virtual machine
- Choose your Azure subscription
- Create a Resources Group or select from an existing one
- Create a name your Virtual Machine
- Select the Region you want the Virtual Machine to be deployed
- Select the availability option according to your need
- Select Security type
- Select VM architectural
- Select the Size of the VM according to the capacity you like to build
Administrative Account
- Create the authentication type
- Create a username
- Select SSH key type
- Select the key pair name
- Select inbound ports name
- Click Review and then create
- Validation pass then create
- Download key after the deployment pass
- Go to resource after the deployment is completed
Step 2: Connect to the Azure VM
- Connect to virtual machine
Enter command prompt at the bottom left, then right click the command prompt to run as Administrator
- Imput the following commands: ssh -i location/key username@IP Address C:\Users\USER\Downloads\Anuola.pem
- Enter yes and sudo apt-get -y update to run the update
- Enter sudo apt-get -y install nginx to install
- Then copy the the Ip address to a browser, here you are welcome to linux virtual machine.
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!