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.
- Access Cloud Shell in your web browser at https://shell.azure.com or in the Azure portal.
- Access Cloud Shell as a terminal from within Visual Studio Code by installing the Azure Account extension.
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
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:
Click Generate. By default PuTTYgen generates a 2048-bit SSH-2 RSA key.
Mouse over the blank area to generate some randomness for the key.
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.
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:
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.
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.
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 myvm.westus.cloudapp.azure.com 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.
Fill in the host name or IP address of your VM from the Azure portal:
Before selecting Open, click Connection > SSH > Auth tab. Browse to and select your PuTTY private key (.ppk file):
Click Open to connect to your VM.
For detailed steps, options, and advanced examples of working with SSH keys, see detailed steps to create SSH key pairs.
You can also use PowerShell in Azure Cloud Shell to generate SSH keys and make SSH connections to Linux VMs. See the PowerShell quickstart.
If you have trouble using SSH to connect to your Linux VMs, see Troubleshoot SSH connections to an Azure Linux VM.