Creating and connecting to a Linux virtual machine (VM) on Azure using SSH public key authentication involves several steps. Here’s a detailed guide to help you through the process:
Step 1: Sign in to Azure Portal
- Sign in: Go to the Azure portal and sign in with your Azure account.
Step 2: Create a Resource Group (if needed)
-
Resource Group: If you don’t have a resource group where you want to deploy the VM, create one:
- Click on Resource groups in the Azure portal's left-hand menu.
- Click + Add to create a new resource group.
- Provide a name, choose a region, and click Review + create then Create.
Step 3: Create a Virtual Machine
-
Create VM: Now, create a new virtual machine:
- In the Azure portal, click + Create a resource at the top-left corner.
- Search for Virtual machine and click Create.
-
Basics:
- Subscription: Choose your Azure subscription.
- Resource Group: Select the resource group you created or an existing one.
- Virtual Machine Name: Provide a name for your VM.
- Region: Choose the Azure region where you want to deploy your VM.
- Image: Choose a Linux distribution (e.g., Ubuntu, CentOS) from the list.
- Size: Select an appropriate VM size based on your requirements.
-
Administrator Account:
-
Username: Choose a username for the administrator account (e.g.,
azureuser
). - Authentication type: Select SSH public key.
-
Username: Choose a username for the administrator account (e.g.,
-
SSH public key: Paste your SSH public key. If you don't have one, generate it using
ssh-keygen
on your local machine (ssh-keygen -t rsa -b 4096
).
-
Disks and other settings:
- Customize the disk configuration, networking, management, and monitoring settings as per your requirements.
-
Review + create:
- Review your configuration settings.
- Click Create to start deploying the VM.
Step 4: Connect to Your Virtual Machine
-
SSH Connection: Once the VM is deployed, you can connect to it using SSH:
- In the Azure portal, go to Virtual machines and select your VM.
- Under Connect, click on SSH.
- Use the SSH command provided to connect to your VM from your local terminal or SSH client.
- Another step is to go to command prompt,run as an administrator and type the SSH command shown below to connect.
ssh -i "/path/to/your/private-key-file.pem" username@your-vm-public-ip
Step 5: Manage and Monitor Your VM
-
Management: Use Azure portal or Azure CLI to manage and monitor your VM:
- Start, stop, restart your VM.
- Scale up or down to change VM sizes.
- Monitor performance and set up alerts.
Step 6: Delete Your VM (if no longer needed)
-
Clean up: If you no longer need the VM, delete it to avoid incurring charges:
- In the Azure portal, go to Virtual machines, select your VM, and click Delete.
Additional Tips:
- Azure CLI: You can also use Azure CLI for VM deployment and management if you prefer command-line tools.
- Templates: Consider using Azure Resource Manager (ARM) templates for consistent and repeatable deployments.
By following these steps, you can create and connect to a Linux VM on Azure using SSH public key authentication securely. Adjust settings based on your specific needs and security requirements.
Top comments (0)