Use SSH keys to connect to Linux VMs - Azure Virtual Machines (2024)

  • Article

Applies to: ✔️ Linux VMs ✔️ Flexible scale sets

This article is for Windows users who want to create and use secure shell (SSH) keys to connect to Linux virtual machines (VMs) in Azure. You can also generate and store SSH keys in the Azure portal to use when creating VMs in the portal.

To use SSH keys from a Linux or macOS client, see the quick steps. For a more detailed overview of SSH, see Detailed steps: Create and manage SSH keys for authentication to a Linux VM in Azure.

Note

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

Overview of SSH and keys

SSH is an encrypted connection protocol that allows secure sign-ins over unsecured connections. SSH is the default connection protocol for Linux VMs hosted in Azure. Although SSH itself provides an encrypted connection, using passwords with SSH still leaves the VM vulnerable to brute-force attacks. We recommend connecting to a VM over SSH using a public-private key pair, also known as SSH keys.

The public-private key pair is like the lock on your front door. The lock is exposed to the public, anyone with the right key can open the door. The key is private, and only given to people you trust because it can be used to unlock the door.

  • The public key is placed on your Linux VM when you create the VM.

  • The private key remains on your local system. Protect this private key. Don't share it.

When you connect to your Linux VM, the VM tests the SSH client to make sure it has the correct private key. If the client has the private key, it's granted access to the VM.

Depending on your organization's security policies, you can reuse a single key pair to access multiple Azure VMs and services. You don't need a separate pair of keys for each VM.

Your public key can be shared with anyone, but only you (or your local security infrastructure) should have access to your private key.

Supported SSH key formats

Azure currently supports SSH protocol 2 (SSH-2) RSA public-private key pairs with a minimum length of 2048 bits. Support for ED25519 Keys is in preview, other key formats such as ECDH and ECDSA are not supported.

Note

During preview, ED25519 keys can only be used with Linux VMs.

SSH clients

Recent versions of Windows 10 include OpenSSH client commands to create and use SSH keys and make SSH connections from PowerShell or a command prompt.

You can also use Bash in the Azure Cloud Shell to connect to your VM. You can use Cloud Shell in a web browser, from the Azure portal, or as a terminal in Visual Studio Code using the Azure Account extension.

You can also install the Windows Subsystem for Linux to connect to your VM over SSH and use other native Linux tools within a Bash shell.

Create an SSH key pair

The easiest way to create and manage your SSH keys is to use the portal to create and store them for reuse.

You can also create key pairs with the Azure CLI with the az sshkey create command, as described in Generate and store SSH keys.

To create an SSH key pair on your local computer using the ssh-keygen command from PowerShell or a command prompt, use the following command:

ssh-keygen -m PEM -t rsa -b 2048

Enter a filename, or use the default shown in parenthesis (for example C:\Users\username/.ssh/id_rsa). Enter a passphrase for the file, or leave the passphrase blank if you don't want to use a passphrase.

Create a VM using your key

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.

az vm create \ --resource-group myResourceGroup \ --name myVM \ --image Ubuntu2204\ --admin-username azureuser \ --ssh-key-value ~/.ssh/id_rsa.pub

With PowerShell, use New-AzVM and add the SSH key to the VM configuration using`. For an example, see Quickstart: Create a Linux virtual machine in Azure with PowerShell.

If you do many deployments using the portal, you might want to upload your public key to Azure, where it can be easily selected when creating a VM from the portal. For more information, see Upload an SSH key.

Connect to your VM

With the public key deployed on your Azure VM, and the private key on your local system, SSH to your VM using the IP address or DNS name of your VM. Replace azureuser and 10.111.12.123 in the following command with the administrator user name, the IP address (or fully qualified domain name), and the path to your private key:

ssh -i ~/.ssh/id_rsa [email protected]

If you've never connected to this VM before you'll be asked to verify the hosts fingerprint. It's tempting to accept the fingerprint presented, however, this exposes you to a possible person in the middle attack. You should always validate the hosts fingerprint. You only need to do this on the first time you connect from a client. To obtain the host fingerprint via the portal, use the Run Command with the following command: ssh-keygen -lf /etc/ssh/ssh_host_ecdsa_key.pub | awk '{print $2}'.

Use SSH keys to connect to Linux VMs - Azure Virtual Machines (1)

To run the command using CLI, use the az vm run-command invoke command.

If you configured a passphrase when you created your key pair, enter the passphrase when prompted.

If the VM is using the just-in-time access policy, you need to request access before you can connect to the VM. For more information about the just-in-time policy, see Manage virtual machine access using the just in time policy.

Next steps

  • For information about SSH keys in the Azure portal to use when creating VMs, see Generate and store SSH keys in the Azure portal.

  • For information about SSH keys in the Azure CLI to use when creating VMs, see Generate and store SSH keys with the Azure CLI.

  • For detailed steps, options, and advanced examples of working with SSH keys, see Detailed steps to create SSH key pairs.

  • If you have difficulty using SSH to connect to your Linux VMs, see Troubleshoot SSH connections to an Azure Linux VM.

Use SSH keys to connect to Linux VMs - Azure Virtual Machines (2024)

FAQs

Can you use SSH keys to connect to an Azure virtual machine? ›

With a secure shell (SSH) key pair, you can create virtual machines (VMs) in Azure that use SSH keys for authentication. This article shows you how to quickly generate and use an SSH public-private key file pair for Linux VMs. You can complete these steps with the Azure Cloud Shell, a macOS, or a Linux host.

How to connect to your Linux virtual machine using SSH? ›

Connecting via SSH
  1. Locate the address of the SSH service. Port opening type. ...
  2. Use the address in a terminal emulation client (such as Putty) or use the following command line to access the VM directly from your desktop SSH client:
  3. ssh -p <port> user@<ip-address-or-hostname>

Which SSH connectivity method to Azure Linux VMs runs directly from the Azure portal over the https protocol? ›

Azure currently supports SSH protocol 2 (SSH-2) RSA public-private key pairs with a minimum length of 2048 bits.

What SSH keys are supported by Azure? ›

The only SSH key type supported by Azure DevOps is RSA. Generating public/private rsa key pair. Enter file in which to save the key (C:\Users\username/.ssh/id_rsa): You can press Enter to accept the default, or specify a path and/or filename where you would like your keys to be generated.

How to use SSH key in VM? ›

To add a public SSH key to instance metadata using the Google Cloud console, do the following:
  1. In the Google Cloud console, go to the VM instances page. ...
  2. Click the name of the VM that you want to add an SSH key for.
  3. Click Edit.
  4. Under SSH Keys, click Add item.
  5. Add your public key into the text box. ...
  6. Click Save.

How to connect two virtual machines using SSH? ›

You create an SSH key pair, add the public key to a VM, and connect to the VM by running the virtctl ssh command with the private key.

How to connect a Linux server using a SSH key? ›

Once your SSH key pair is generated, you need to place the public key on the server.
  1. Use the command `ssh-copy-id user@your_server_ip` to copy the public key. Replace `user` with your username and `your_server_ip` with your server's IP address.
  2. Enter your password when prompted.
Jul 10, 2019

How to connect with SSH on Linux? ›

For Linux
  1. Connect via SSH Command. Open a terminal and enter the following command: ssh @ . For example, if the IP address is 192.168. ...
  2. Enter Yes to Continue. When prompted with a warning message that says "The authenticity of host 'xxx' can't be established", enter "yes" to continue with the connection.
Feb 21, 2023

Which command is used to connect to a Linux virtual machine using SSH? ›

Logging into a Linux Virtual Machine via SSH with a Username and Password. Using the console or command line, use the ssh user@host command to access the server.

How do I connect to Azure VM from Linux? ›

Prerequisites
  1. You need an SSH key pair. If you don't already have one, Azure creates a key pair during the deployment process. ...
  2. You need an existing Network Security Group (NSG). ...
  3. To connect to a Linux VM, you need the appropriate port open. ...
  4. Your VM must have a public IP address. ...
  5. Verify your VM is running.
Aug 22, 2024

What are all the ways to connect to the VMS in 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 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 access a Linux virtual machine via SSH from Windows? ›

Check in “Installed features” if the OpenSSH client is installed, if not click Add a feature, search for OpenSSH client and install it.
  1. Step 1 Go to the folder containing your SSH keys. Run the Command Prompt and change the current folder to the folder where you store your keys. ...
  2. Step 2 Connect to your VM using SSH.

How to see your SSH key in Linux? ›

How to view your SSH public key on Linux
  1. Using the ssh-agent command.
  2. Run the following command. ssh-agent sh -c 'ssh-add; ssh-add -L'
  3. After successful authentication, your SSH public key will be displayed in the terminal.
  4. Copy and paste it where you need it.
Sep 12, 2023

Where are SSH keys used? ›

As the SSH protocol is widely used for communication in cloud services, network environments, file transfer tools, configuration management tools, and other computer-dependent services, most organizations use this type of key-based authentication to verify identities and protect those services from unintended use or ...

How to SSH to Azure 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 to connect to Azure 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.

Does SSH allow remote access? ›

SSH is a powerful tool for remote access. It allows you to log in and run commands on a remote machine just as if you were sitting in front of it. Many sysadmins use custom prompts for remote machines to avoid confusing a local terminal with a remote one.

Top Articles
Award Winning Water
Common Mistakes in Contract Writing – Business Law and Ethics Canadian Edition
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
Non Sequitur
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 5723

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.