Azure virtual machines (VMs) can be created through the Azure portal. This method provides a browser-based user interface to create VMs and their associated resources. This blog post shows you how to use the Azure portal to create a virtual machine (VM) that runs on Linux server and connect using Powershell.
In this blog you will see how to create and connect a Linux VM using public key.Public key authentication allows you to access a server via ssh without password.
If you don't have an Azure subscription, create a free account before you begin.
Sign in to Azure
Sign in to the Azure portal.
Create virtual machine
Enter virtual machines in the search.
Under Services, select Virtual machines.
Subscription: Choose the appropriate subscription.
Resource Group: Create a new or select an existing resource group.
Virtual machine name: Give your VM a unique name.
Region: Choose the data center region of your choice, preferably a region closest to you.
Availability options: Select the availability preferences.
Choose a linux server for the Image.
- Select size of the memory
Security and Authentication
Authenticator type - Select SSH public key
Azure will automatically generate an SSH key pair for you to
store for future use. It is a fast simple and secure way to
connect to the VM.Enter key pair name
Public inbound ports- Select allow selected ports
Select HTTP(80),SSH(22)
Click Review + Create
- VM is validated and shows the costing information.
- Select create.
Download private key and create resource
The private key will be saved in the computer.
Deployment is complete
VM is ready
Here we can see all the details on the VM that was just created. Copy the public IP address because we would use it to connect.
Connecting to the VM using power shell
- Navigate to Windows Powershell on a PC.
- Run this command the command below
ssh -i "path to the private key on the pc" username@publicIP
After connecting to the VM,we run some sudo commands to test
sudo apt-get -y update
Testing Public IP on a Browser
Clean Up
After creating and deploying the Vm, since this project is just for practice.We clean up by deleting the resource group to avoid incurring cost.
- Search for resource group
- Select the resource group that was created for this VM
- Select all resources that were created
- Click delete
- Enter resource group name to confirm deletion
Conclusion
With a secure shell (SSH) key pair, you can create virtual machines (VMs) in Azure that use SSH keys for authentication. This article elaborates on how to quickly generate and use an SSH public-private key file pair for Linux VMs.
Top comments (0)