Loading Now

A Beginner’s Guide to Connecting to Azure VMs via SSH

A Beginner's Guide to Connecting to Azure VMs via SSH

A Beginner’s Guide to Connecting to Azure VMs via SSH

Azure Virtual Machines (VMs) are an essential component of Microsoft’s cloud computing platform, allowing users to run applications and services in a scalable and flexible environment. For beginners looking to delve into the world of cloud computing, connecting to an Azure VM via SSH (Secure Shell) is often one of the first steps. This guide will walk you through the process, providing helpful tips and troubleshooting advice.

What is SSH?

SSH, or Secure Shell, is a cryptographic network protocol that enables secure communication between a client and a server. It is primarily used for remote administration of systems and secure file transfers. When it comes to Azure VMs, SSH provides a safe way to connect to your virtual machine, execute commands, and manage files.

Pre-requisites

Before you can connect to your Azure VM using SSH, you will need:

  1. An Azure subscription: You can sign up for a free account on the Azure portal if you don’t already have one.
  2. A created Azure VM: If you haven’t set one up yet, navigate to the Azure portal and create a new VM. Ensure that you choose a Linux-based operating system, as this guide focuses on SSH connections typical for such environments.
  3. SSH client: Most Linux and macOS systems come with an SSH client pre-installed. For Windows users, options include Windows Subsystem for Linux (WSL), PuTTY, or the built-in SSH client in Windows 10 and later.

Step-by-Step Guide to Connect to Azure VM

Step 1: Configure Network Security Groups (NSGs)

When creating your Azure VM, you must configure its Network Security Group (NSG) to allow SSH connections. Ensure that:

  • The NSG attached to your VM’s network interface allows inbound traffic on port 22 (the default SSH port).

To do this:

  1. Navigate to the Azure portal and select your VM.
  2. Under the Networking tab, locate the NSG associated with your VM.
  3. Click on Inbound security rules and ensure there is a rule allowing TCP traffic on port 22.

Step 2: Obtain the Public IP Address

You will need the public IP address of your Azure VM to connect via SSH. You can find this information in the Azure portal:

  1. Select your VM from the Virtual Machines list.
  2. Copy the Public IP address displayed on the overview page.

Step 3: Connect Using an SSH Client

On Linux or macOS

  1. Open your terminal.

  2. Use the following command to connect to your VM:

    bash
    ssh username@public_ip_address

    Replace username with the username you specified when creating the VM and public_ip_address with the VM’s public IP.

  3. If this is your first connection to the VM, you will be prompted to confirm the authenticity of the host. Type yes to proceed.

  4. Enter your password when prompted.

On Windows (Using Command Prompt or PowerShell)

  1. Open Command Prompt or PowerShell.

  2. Use the same SSH command as above:

    powershell
    ssh username@public_ip_address

On Windows (Using PuTTY)

  1. Download and install PuTTY if you haven’t done so already.
  2. Open PuTTY.
  3. In the Host Name (or IP address) field, enter your VM’s public IP address.
  4. Ensure the port is set to 22 and the connection type is set to SSH.
  5. Click Open to initiate the connection. You will be prompted for your username and password.

Step 4: Secure Your Connection

For enhanced security, consider disabling password authentication and using SSH keys instead. Here’s how to set up SSH keys:

  1. Generate an SSH key pair on your local machine (Linux/macOS):

    bash
    ssh-keygen -t rsa -b 2048

    Follow the prompts to save your keys, usually in the ~/.ssh/ directory.

  2. Copy the public key to your VM:

    bash
    ssh-copy-id username@public_ip_address

  3. Once added, you can connect without a password. Just run the SSH command again:

    bash
    ssh username@public_ip_address

Troubleshooting Common Issues

  • Connection Timeout: Ensure that the NSG is correctly configured to allow inbound SSH traffic on port 22.
  • Authentication Failed: Double-check the username and password or ensure the public key has been correctly added to the VM.
  • SSH Client Not Recognised: For Windows users using Command Prompt or PowerShell, ensure that the Azure CLI is installed and properly configured.

Conclusion

Connecting to Azure VMs via SSH is a straightforward process that opens up vast possibilities for cloud management and application deployment. By following the steps outlined in this guide, beginners will gain the confidence to navigate and manage their Azure environment efficiently. As you become more familiar with Azure, exploring additional features and best practices will further enhance your cloud experience. Happy computing!

Share this content:

Post Comment