How to use SSH keys with Windows on Azure

This article introduces ways to generate and use secure shell (SSH) keys on a Windows computer to create and connect to a Linux virtual machine (VM) in Azure. To use SSH keys from a Linux or macOS client, see the quick or detailed guidance.

Overview of SSH and keys

SSH is an encrypted connection protocol that allows secure logins over unsecured connections. It is the default connection protocol for Linux VMs hosted in Azure. Although SSH itself provides an encrypted connection, using passwords with SSH connections still leaves the VM vulnerable to brute-force attacks or guessing of passwords. A more secure and preferred method of connecting to a VM using SSH is by using a public-private key pair, also known as SSH keys.

  • The public key is placed on your Linux VM, or any other service that you wish to use with public-key cryptography.

  • The private key is what you present to your Linux VM when you make an SSH connection, to verify your identity. Protect this private key. Do not share it.

Depending on your organization's security policies, you can reuse a single public-private key pair to access multiple Azure VMs and services. You do not need a separate pair of keys for each VM or service you wish to access.

Your public key can be shared with anyone; but only you (or your local security infrastructure) possess 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. Other key formats such as ED25519 and ECDSA are not supported.

Windows packages and SSH clients

You connect to and manage Linux VMs in Azure using an SSH client. Computers running Linux or macOS usually have a suite of SSH commands to generate and manage SSH keys and to make SSH connections.

Windows computers do not always have comparable SSH commands installed. Windows 10 versions that include the Windows Subsystem for Linux allow you to run and access utilities such as an SSH client natively within a Bash shell.

If you wish to use something other than Bash for Windows, common Windows SSH clients you can install locally are included in the following packages:

Another option is to use the SSH utilities available in Bash in the Azure Cloud Shell.

Create an SSH key pair

This section shows you two options to create an SSH key pair on Windows.

Create SSH keys with ssh-keygen

If you can run a command shell such as Bash for Windows or GitBash (or Bash in Azure Cloud Shell), create an SSH key pair using the ssh-keygen command. Type the following command, and answer the prompts. If an SSH key pair exists in the current location, those files are overwritten.

ssh-keygen -t rsa -b 2048

For more background and information, see the quick or detailed steps to create the keys with ssh-keygen.

Create SSH keys with PuTTYgen

If you prefer to use a GUI-based tool to create SSH keys, you can use the PuTTYgen key generator, included with the PuTTY download package.

To create an SSH RSA key pair with PuTTYgen:

  1. Start PuTTYgen.

  2. Click Generate. By default PuTTYgen generates a 2048-bit SSH-2 RSA key.

  3. Mouse over the blank area to generate some randomness for the key.

  4. After the public key is generated, optionally enter and confirm a passphrase. You will be prompted for the passphrase when you authenticate to the VM with your SSH key. Without a passphrase, if someone obtains your private key, they can log in to any VM or service that uses that key. We recommend you create a passphrase. However, if you forget the passphrase, there is no way to recover it.

  5. The public key is displayed at the top of the window. You copy and paste this one-line format public key into the Azure portal or an Azure Resource Manager template when you create a Linux VM. You can also click Save public key to save a copy to your computer:

    Save PuTTY public key file

  6. Optionally, to save the private key in PuTTy private key format (.ppk file), click Save private key. You need the .ppk file of you want to use PuTTY later to make an SSH connection to the VM.

    Save PuTTY private key file

    If you want to save the private key in the OpenSSH format, the private key format used by many SSH clients, click Conversions > Export OpenSSH key.

Provide SSH public key when deploying a VM

To create a Linux VM that uses SSH keys for authentication, provide your SSH public key when creating the VM using the Azure portal or other methods.

The following example shows how you would copy and paste this public key into the Azure portal when you create a Linux VM. The public key is typically then stored in ~/.ssh/authorized_keys on your new VM.

Use public key when you create a VM in the Azure portal

Connect to your VM

One way to make an SSH connection to your Linux VM from Windows is to use an SSH client. This is the preferred method if you have an SSH client installed on your Windows system, or you use SSH tools in Bash in Azure Cloud Shell. If you prefer a GUI-based tool, you can connect with PuTTY.

Use an SSH client

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 in the following command with the administrator user name and the fully qualified domain name (or IP address):


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

Connect with PuTTY

If you installed the PuTTY download package and previously generated a PuTTY private key (.ppk file), you can connect to the Linux VM with PuTTY.

  1. Start PuTTy.

  2. Fill in the host name or IP address of your VM from the Azure portal:

    Open new PuTTY connection

  3. Before selecting Open, click Connection > SSH > Auth tab. Browse to and select your PuTTY private key (.ppk file):

    Select your PuTTY private key for authentication

  4. Click Open to connect to your VM.

Next steps