Connect to a Linux VM - Azure Virtual Machines (2024)

  • Article

When hosting a Linux virtual machine on Azure, the most common method for accessing that VM is through the Secure Shell Protocol (SSH). Any standard SSH client commonly found in Linux and Windows allows you to connect. You can also use Azure Cloud Shell from any browser.

This document describes how to connect, via SSH, to a VM that has a public IP. If you need to connect to a VM without a public IP, see Azure Bastion Service.

Note

ED25519 SSH key support for Linux VMs is now in preview in all regions including sovereign clouds.

Prerequisites

  • You need an SSH key pair. If you don't already have one, Azure creates a key pair during the deployment process. If you need help with creating one manually, see Create and use an SSH public-private key pair for Linux VMs in Azure.

  • You need an existing Network Security Group (NSG). Most VMs have an NSG by default, but if you don't already have one you can create one and attach it manually. For more information, see Create, change, or delete a network security group.

  • To connect to a Linux VM, you need the appropriate port open. Typically SSH uses port 22. The following instructions assume port 22 but the process is the same for other port numbers. You can validate an appropriate port is open for SSH using the troubleshooter or by checking manually in your VM settings. To check if port 22 is open:

    1. On the page for the VM, select Networking from the left menu.

    2. On the Networking page, check to see if there's a rule that allows TCP on port 22 from the IP address of the computer you're using to connect to the VM. If the rule exists, you can move to the next section.

      Connect to a Linux VM - Azure Virtual Machines (1)

    3. If there isn't a rule, add one by selecting Add inbound port rule.

    4. For Service, select SSH from the dropdown.

      Connect to a Linux VM - Azure Virtual Machines (2)

    5. Edit Priority and Source if necessary

    6. For Name, type SSH.

    7. When you're done, select Add.

    8. You should now have an SSH rule in the table of inbound port rules.

  • Your VM must have a public IP address. To check if your VM has a public IP address, select Overview from the left menu and look at the Networking section. If you see an IP address next to Public IP address, then your VM has a public IP

    If your VM doesn't have a public IP Address, it looks like this:

    Connect to a Linux VM - Azure Virtual Machines (3)

    To learn more about adding a public IP address to an existing VM, see Associate a public IP address to a virtual machine

  • Verify your VM is running. On the Overview tab, in the Essentials section, verify the status of the VM is Running. To start the VM, select Start at the top of the page.

    Connect to a Linux VM - Azure Virtual Machines (4)

If you're having trouble connecting, you can also use portal:

  1. Go to the Azure portal to connect to a VM. Search for and select Virtual machines.
  2. Select the virtual machine from the list.
  3. Select Connect from the left menu.
  4. Select the option that fits with your preferred way of connecting. The portal helps walk you through the prerequisites for connecting.

Connect to the VM

Once the above prerequisites are met, you're ready to connect to your VM. Open your SSH client of choice. The SSH client command is typically included in Linux, macOS, and Windows. If you're using Windows 7 or older, where Win32 OpenSSH isn't included by default, consider installing WSL or using Azure Cloud Shell from the browser.

Note

The following examples assume the SSH key is in the key.pem format. If you used CLI or Azure PowerShell to download your keys, they may be in the id_rsa or ED25519 format.

  • WSL, macOS, or native Linux client
  • Windows command line (cmd.exe, PowerShell etc.)

SSH with a new key pair

  1. Ensure your public and private keys are in the correct directory. The directory is usually ~/.ssh.

    If you generated keys manually or generated them with the CLI, then the keys are probably already there. However, if you downloaded them in pem format from the Azure portal, you may need to move them to the right location. Moving the keys is done with the following syntax: mv PRIVATE_KEY_SOURCE PRIVATE_KEY_DESTINATION

    For example, if the key is in the Downloads folder, and myKey.pem is the name of your SSH key, type:

    mv /Downloads/myKey.pem ~/.ssh

    Note

    If you're using WSL, local files are found in the mnt/c/ directory. Accordingly, the path to the downloads folder and SSH key would be /mnt/c/Users/{USERNAME}/Downloads/myKey.pem

  2. Ensure you have read-only access to the private key by running

    chmod 400 ~/.ssh/myKey.pem
  3. Run the SSH command with the following syntax: ssh -i PATH_TO_PRIVATE_KEY USERNAME@EXTERNAL_IP

    For example, if your azureuser is the username you created and 20.51.230.13 is the public IP address of your VM, type:

    ssh -i ~/.ssh/myKey.pem [email protected]
  4. Validate the returned fingerprint.

    If you have never connected to this VM before, you're asked to verify the hosts fingerprint. It's tempting to accept the fingerprint presented, but that exposes you to a potential person in the middle attack. You should always validate the hosts fingerprint. You only need to do this the first time you connect from a client. To get the host fingerprint via the portal, use the Run Command feature to execute the command:

    ssh-keygen -lf /etc/ssh/ssh_host_ecdsa_key.pub | awk '{print $2}'
  5. Success! You should now be connected to your VM. If you're unable to connect, see Troubleshoot SSH connections.

SSH With existing public key

  1. Run the following command in your SSH client. In this example, 20.51.230.13 is the public IP Address of your VM and azureuser is the username you created when you created the VM.

    ssh [email protected]
  2. Validate the returned fingerprint.

    If you have never connected to the desired VM from your current SSH client before you're asked to verify the host's fingerprint. While the default option is to accept the fingerprint presented, you're exposed to a possible "person in the middle attack". You should always validate the host's fingerprint, which only needs to be done the first time your client connects. To obtain the host fingerprint via the portal, use the Run Command feature to execute the command:

    ssh-keygen -lf /etc/ssh/ssh_host_ecdsa_key.pub | awk '{print $2}'
  3. Success! You should now be connected to your VM. If you're unable to connect, see our troubleshooting guide.

Password authentication

Warning

This type of authentication method is not as secure as an SSH key pair and is not recommended.

  1. Run the following command in your SSH client. In this example, 20.51.230.13 is the public IP Address of your VM and azureuser is the username you created when you created the VM.

    ssh [email protected]

    If you forgot your password or username see Reset Access to an Azure VM

  2. Validate the returned fingerprint.

    If you have never connected to the desired VM from your current SSH client before you're asked to verify the host's fingerprint. While the default option is to accept the fingerprint presented, you're exposed to a possible "person in the middle attack". You should always validate the host's fingerprint, which only needs to be done the first time your client connects. To obtain the host fingerprint via the portal, use the Run Command feature to execute the command:

    ssh-keygen -lf /etc/ssh/ssh_host_ecdsa_key.pub | awk '{print $2}'
  3. Success! You should now be connected to your VM. If you're unable to connect, see Troubleshoot SSH connections.

Next steps

Learn how to transfer files to an existing VM, see Use SCP to move files to and from a VM.

Connect to a Linux VM - Azure Virtual Machines (2024)

FAQs

Connect to a Linux VM - Azure Virtual Machines? ›

Go to the Azure portal to connect to a VM. Search for and select Virtual machines. Select the virtual machine from the list. Select Connect from the left menu.

How do I Connect to a Linux virtual machine? ›

Connect to a VM using SSH by running the gcloud compute ssh command:
  1. In the Google Cloud console, activate Cloud Shell. Activate Cloud Shell. ...
  2. Run the following command: gcloud compute ssh --project= PROJECT_ID --zone= ZONE VM_NAME.

How to connect to Azure Linux VM with private IP? ›

Connect to VM - Azure portal

To connect to a VM using a specified private IP address, you make the connection from Bastion to the VM, not directly from the VM page. On your Bastion page, select Connect to open the Connect page. On the Bastion Connect page, for IP address, enter the private IP address of the target VM.

How to get root access in Azure Linux VM? ›

Log into the Linux virtual machine using SSH key or password authentication, then run commands using sudo , for example: # sudo <command> [sudo] password for azureuser: In this case the user will be prompted for a password. After entering the password sudo will run the command with root privileges.

How to connect Azure Linux VM using PuTTY? ›

Open PuTTY:
  1. For Connection type, make sure the SSH radio button is selected.
  2. In the Host Name field, enter azureuser@<public ip> (your admin username and IP will vary)
  3. On the left, expand the SSH section, and click on Auth.
  4. Click on Browse to look for your private key (. ...
  5. To launch the SSH session, click Open.

How do I open Linux on a virtual machine? ›

2.1. Creating a Linux Virtual Machine
  1. Click the Virtual Machines tab.
  2. Click the New VM button to open the New Virtual Machine window. ...
  3. Select a Linux variant from the Operating System drop-down list.
  4. Enter a Name for the virtual machine.
  5. Add storage to the virtual machine. ...
  6. Connect the virtual machine to the network.

How to access Linux VM from Windows? ›

SSH with a new key pair
  1. Locate your private SSH Key.
  2. Run the SSH command with the following syntax: ssh -i PATH_TO_PRIVATE_KEY USERNAME@EXTERNAL_IP. For example, if your azureuser is the username you created and 20.51.230.13 is the public IP address of your VM, type: ...
  3. Validate the returned fingerprint. ...
  4. Success!
Aug 22, 2024

How do I login as root in Linux VM? ›

Enable root login by doing the following:
  1. Create an SSH key. ...
  2. Connect to the VM as you usually do.
  3. Change PermitRootLogin no to PermitRootLogin prohibit-password in the /etc/ssh/sshd_config file, by running the following command: ...
  4. Create the /root/. ...
  5. Set permissions on the .

How to set root password in Azure Linux VM? ›

Reset the password by using the serial console with single-user mode. You can use the serial console to reset the admin user or root account through single-user mode for VM access. Follow the single-user mode process to reset or add a password.

How to connect linux virtual machine via PuTTY? ›

How to Connect to a Linux VM using Putty
  1. Start PuTTy.
  2. Fill in the host name or IP address of your VM from the Azure portal:
  3. Before selecting Open, click Connection > SSH > Auth tab. Browse to and select your PuTTY private key (.ppk file):
  4. Click Open to connect to your VM.
Sep 30, 2020

How to connect SSH to Azure Linux VM? ›

To create a Linux VM that uses SSH keys for authentication, provide your SSH public key when creating the VM. Using the Azure CLI, you specify the path and filename for the public key using az vm create and the --ssh-key-value parameter. With PowerShell, use New-AzVM and add the SSH key to the VM configuration using`.

How to connect to VM on Azure? ›

Connect from Azure portal
  1. Go to the Azure portal to connect to a VM. Search for and select Virtual machines.
  2. Select the virtual machine from the list.
  3. Select Connect from the left menu.
  4. Select the option that fits with your preferred way of connecting. The portal helps walk you through the prerequisites for connecting.
Aug 23, 2024

How do you connect to a Linux machine server? ›

Windows
  1. From the Start Menu, open Remote Desktop Connection (Tip: Click the Windows button and type 'remote'. ...
  2. The Remote Desktop Connection window will open.
  3. For “Computer”, type the name or alias of one of the Linux servers.
  4. If a dialog box appears asking about the authenticity of the host, answer “Yes”.

How do I connect to a Linux virtual machine using remote desktop? ›

To connect to the Linux VM via RDP, you must have the following ports open on your VM:
  1. Inbound port: RDP (3389) or.
  2. Inbound port: Custom value (you'll then need to specify this custom port when you connect to the VM via Azure Bastion)
Jun 20, 2024

How do I login to a VM? ›

To connect with Microsoft Windows Remote Desktop, do the following:
  1. Create a Windows account and password if you do not have one yet.
  2. To connect over the internet, use the external IP address. ...
  3. Open Microsoft Windows Remote Desktop Connection on your Windows machine. ...
  4. In the Computer box, enter the IP address.

Top Articles
Buffett Indicator labels Indian market as ’modestly overvalued’; projects 5.8% annual returns, lowest among EM peers | Stock Market News
1. Add a debit or credit card
What Is Single Sign-on (SSO)? Meaning and How It Works? | Fortinet
Room Background For Zepeto
Summit County Juvenile Court
Google Sites Classroom 6X
Find All Subdomains
DL1678 (DAL1678) Delta Historial y rastreo de vuelos - FlightAware
Is Csl Plasma Open On 4Th Of July
Paketshops | PAKET.net
Lesson 1 Homework 5.5 Answer Key
About Goodwill – Goodwill NY/NJ
Sams Early Hours
Painting Jobs Craigslist
Burn Ban Map Oklahoma
Craftology East Peoria Il
Mflwer
Csi Tv Series Wiki
TBM 910 | Turboprop Aircraft - DAHER TBM 960, TBM 910
Aldi Bruce B Downs
Cvs El Salido
Https Paperlesspay Talx Com Boydgaming
Www.dunkinbaskinrunsonyou.con
Sunset Time November 5 2022
Mta Bus Forums
Divide Fusion Stretch Hoodie Daunenjacke für Herren | oliv
Danielle Moodie-Mills Net Worth
Marlene2995 Pagina Azul
Cinema | Düsseldorfer Filmkunstkinos
Log in to your MyChart account
Courtney Roberson Rob Dyrdek
Guide to Cost-Benefit Analysis of Investment Projects Economic appraisal tool for Cohesion Policy 2014-2020
Wake County Court Records | NorthCarolinaCourtRecords.us
Lowell Car Accident Lawyer Kiley Law Group
Tendermeetup Login
Peter Vigilante Biography, Net Worth, Age, Height, Family, Girlfriend
Asian Grocery Williamsburg Va
Austin Automotive Buda
How To Get Soul Reaper Knife In Critical Legends
Blackwolf Run Pro Shop
The Wait Odotus 2021 Watch Online Free
Unveiling Gali_gool Leaks: Discoveries And Insights
Levi Ackerman Tattoo Ideas
Arcanis Secret Santa
Professors Helpers Abbreviation
705 Us 74 Bus Rockingham Nc
Caesars Rewards Loyalty Program Review [Previously Total Rewards]
877-552-2666
Plumfund Reviews
Ssss Steakhouse Menu
Vt Craiglist
Who We Are at Curt Landry Ministries
Latest Posts
Article information

Author: Stevie Stamm

Last Updated:

Views: 5580

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Stevie Stamm

Birthday: 1996-06-22

Address: Apt. 419 4200 Sipes Estate, East Delmerview, WY 05617

Phone: +342332224300

Job: Future Advertising Analyst

Hobby: Leather crafting, Puzzles, Leather crafting, scrapbook, Urban exploration, Cabaret, Skateboarding

Introduction: My name is Stevie Stamm, I am a colorful, sparkling, splendid, vast, open, hilarious, tender person who loves writing and wants to share my knowledge and understanding with you.