Using SSH keys, creating and connecting to a Linux VM ensures a secure and password-less login. Below is a step-by-step guide to help you set up and connect to a Linux VM using a public key.
Create a Linux VM on Azure
Login to Azure Portal
Click on *"Create a resource"
*
Click on "Virtual machine"
Configure Basic Settings:
Subscription: Select your subscription.
Resource Group: Create a new resource group or use an existing one.
Virtual Machine Name: Enter a name for your VM.
Region: Select your preferred region.
Image: Ensure "Ubuntu Server" is selected.
Size: Choose an appropriate size for your VM.
Administrator Account:
Authentication Type: Select "SSH public key".
Username: Enter a username of your choice.
SSH Public Key Source: Select "Generate new key pair".
SSH Key Type: Select "RSA SSH Format".
Select inbound ports: Select "HTTP(80), SSH(22)".
Disks: Configure the disk settings as needed.
Networking: Configure network settings
Management, Advanced, and Tags: Configure additional settings if needed. Leave at default for beginner learning.
Review + Create: Review your settings and click "Create".
Connect to Your Azure VM
Download private key:
Deployment in progress
When "Deployment is complete" Select "Go to resource".
Retrieve Public IP Address:
Go to the "Virtual Machines" section in the Azure portal.
Select your VM.
Copy the public IP address of your VM.
Connect Using SSH:
Open Terminal (Linux/Mac) or PowerShell (Windows) and connect to your VM using the private key.
Install web server:
*View of the web server:
*
Troubleshooting Tips
Permission Denied (Publickey): Ensure the public key is correctly added during VM creation and the username is correct.
File Not Accessible: Verify the file path and permissions of your private key.
Connection Issues: Ensure the network security group (NSG) rules allow inbound traffic on port 22.
Conclusion
Using SSH keys for authentication enhances the security of your connections to Linux VMs. By following these steps, you can easily create and connect to a Linux VM using a public key on Azure, ensuring a secure and password-less login.
Top comments (0)